@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.
- package/package.json +3 -1
- package/src/account/auth-dialog.tsx +19 -1
- package/src/account/billing.ts +2 -1
- package/src/account/heard-from-question.tsx +235 -0
- package/src/account/heard-from.ts +97 -0
- package/src/api-client/cot.ts +5 -6
- package/src/api-client/data.ts +14 -3
- package/src/api-client/heard-from.ts +72 -0
- package/src/api-client/index.ts +64 -6
- package/src/api-client/mna.ts +18 -0
- package/src/api-client/request.ts +162 -40
- package/src/api-client/supply-chain.ts +9 -0
- package/src/api-client/types/billing.ts +35 -1
- package/src/api-client/types/news.ts +45 -0
- package/src/api-client/types/world-venues.ts +9 -0
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pro-welcome/keys.ts +27 -0
- package/src/app/pro-welcome/model.ts +158 -0
- package/src/app/pro-welcome/row.tsx +176 -0
- package/src/app/pro-welcome/use-pro-welcome.ts +156 -0
- package/src/app/runtime/external-profile-changes.ts +135 -0
- package/src/app.tsx +37 -4
- package/src/architecture/core-builtin-allowlist.json +1 -1
- package/src/architecture/floating-promise-allowlist.json +1 -2
- package/src/architecture/shortcut-labels-allowlist.json +1 -0
- package/src/cli/alert-listing.ts +98 -0
- package/src/cli/commands/market.ts +191 -39
- package/src/cli/commands/overview.ts +7 -1
- package/src/cli/commands/plugins.ts +3 -2
- package/src/cli/commands/search.ts +30 -6
- package/src/cli/commands/ticker.ts +13 -6
- package/src/cli/context.ts +24 -5
- package/src/cli/csv-export.ts +2 -1
- package/src/cli/desktop-pane-shot-browser.ts +3 -1
- package/src/cli/desktop-pane-shot-view.ts +0 -1
- package/src/cli/desktop-pane-shot.ts +276 -52
- package/src/cli/errors.ts +3 -9
- package/src/cli/exit-codes.ts +1 -1
- package/src/cli/glossary.ts +65 -11
- package/src/cli/help.ts +1 -1
- package/src/cli/history-demergers.ts +117 -0
- package/src/cli/history-rows.ts +8 -4
- package/src/cli/index.ts +2 -1
- package/src/cli/known-gaps.ts +16 -0
- package/src/cli/known-us-stocks.ts +18 -0
- package/src/cli/listing-arg.ts +192 -38
- package/src/cli/pane-functions/catalog-snapshot-build.ts +83 -0
- package/src/cli/pane-functions/catalog-snapshot.json +877 -0
- package/src/cli/pane-functions/catalog-snapshot.ts +62 -0
- package/src/cli/pane-functions/catalog.ts +50 -16
- package/src/cli/pane-functions/data.ts +16 -4
- package/src/cli/pane-functions/dom.ts +54 -8
- package/src/cli/pane-functions/freshness.ts +39 -4
- package/src/cli/pane-functions/function-help.ts +3 -3
- package/src/cli/pane-functions/headless.ts +9 -1
- package/src/cli/pane-functions/index.ts +175 -50
- package/src/cli/pane-functions/report-notices.ts +10 -0
- package/src/cli/pane-functions/resolver.ts +11 -7
- package/src/cli/pane-functions/screenshot-assessment.ts +38 -10
- package/src/cli/pane-functions/screenshot-data-evidence.ts +7 -15
- package/src/cli/pane-functions/screenshot-payload.ts +36 -1
- package/src/cli/pane-functions/screenshot-render.ts +24 -9
- package/src/cli/pane-functions/screenshot-types.ts +9 -0
- package/src/cli/quote-answer.ts +33 -17
- package/src/cli/registry.ts +22 -2
- package/src/cli/result.ts +22 -4
- package/src/cli/scroll-truncation.ts +7 -2
- package/src/cli/series-search.ts +45 -6
- package/src/cli/shot-temp-dir.ts +4 -9
- package/src/cli/ticker-resolution.ts +1 -1
- package/src/cli/unreachable.ts +21 -0
- package/src/components/chart/composite/drawing-store.ts +11 -7
- package/src/components/chart/composite/format.ts +1 -0
- package/src/components/chart/composite/legend.tsx +48 -20
- package/src/components/chart/composite/panel-surface/panel-cursor.tsx +3 -3
- package/src/components/chart/composite/panel-surface/plot-gestures.ts +9 -2
- package/src/components/chart/composite/panel-surface.tsx +1 -1
- package/src/components/chart/composite/price-axis-labels.tsx +7 -5
- package/src/components/chart/composite/tools.ts +164 -39
- package/src/components/chart-table/header.tsx +11 -2
- package/src/components/chart-table/layout.ts +16 -17
- package/src/components/command-bar/pane-templates/items.ts +17 -1
- package/src/components/command-bar/routes/root/provider-search.ts +10 -1
- package/src/components/command-bar/routes/root/results.ts +34 -2
- package/src/components/command-bar/routes/root/runtime.ts +19 -4
- package/src/components/command-bar/routes/ticker-search/results.ts +5 -0
- package/src/components/command-bar/routes/ticker-search/route.ts +5 -0
- package/src/components/command-bar/selection-runtime.ts +29 -5
- package/src/components/command-bar/surface/index.tsx +4 -1
- package/src/components/command-bar/workflow/alert.ts +32 -13
- package/src/components/data-table/view.tsx +15 -2
- package/src/components/form-modal/content.tsx +9 -4
- package/src/components/index.ts +1 -1
- package/src/components/layout/header.tsx +9 -5
- package/src/components/layout/pane/capture-status.ts +6 -0
- package/src/components/layout/pane/footer/index.tsx +2 -0
- package/src/components/layout/pane/footer/model.ts +123 -17
- package/src/components/layout/pane/header.tsx +16 -2
- package/src/components/layout/pane/status-footer.ts +24 -0
- package/src/components/market-board/index.tsx +4 -2
- package/src/components/onboarding/onboarding-frame.tsx +6 -2
- package/src/components/onboarding/onboarding-keyboard.ts +7 -1
- package/src/components/onboarding/onboarding-wizard.tsx +3 -1
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +24 -15
- package/src/components/onboarding/setup-cards.ts +36 -0
- package/src/components/onboarding/use-onboarding-progress.ts +22 -1
- package/src/components/onboarding/wizard-account.ts +6 -1
- package/src/components/onboarding/wizard-model.ts +32 -6
- package/src/components/onboarding/wizard-positions.ts +1 -1
- package/src/components/price-performance.tsx +26 -8
- package/src/components/reader/article-reader.tsx +12 -5
- package/src/components/sign-in-gate.tsx +3 -1
- package/src/components/toggle-list.tsx +6 -8
- package/src/components/ui/confirm-dialog.tsx +47 -7
- package/src/components/ui/data-table/opentui/index.tsx +7 -0
- package/src/components/ui/data-table/types.ts +8 -0
- package/src/components/ui/display.tsx +17 -2
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/stat-grid.tsx +4 -0
- package/src/components/ui/status.tsx +13 -1
- package/src/components/ui/table-layout.ts +34 -2
- package/src/components/use-pane-notice-footer.tsx +16 -3
- package/src/data/config/store/index.ts +31 -0
- package/src/data/config/store/node.ts +61 -11
- package/src/data/config/store/normalize.ts +4 -6
- package/src/data/config/store/shared-file.ts +309 -0
- package/src/data/profile-merge.ts +299 -0
- package/src/data/sqlite/checkpointer.ts +11 -1
- package/src/data/sqlite/database.ts +1 -1
- package/src/data/ticker-repository.ts +134 -10
- package/src/data/ticker-store.ts +67 -0
- package/src/data/ticker-writes.ts +5 -0
- package/src/i18n/es.ts +27 -0
- package/src/i18n/ja.ts +27 -0
- package/src/i18n/ko.ts +27 -0
- package/src/i18n/zh-cn.ts +27 -0
- package/src/i18n/zh-tw.ts +27 -0
- package/src/layout-marketplace/gallery-desktop.tsx +2 -2
- package/src/market-data/ah-pair.ts +122 -0
- package/src/market-data/coordinator/entries.ts +6 -4
- package/src/market-data/coordinator/index.ts +14 -3
- package/src/market-data/depositary-pair.ts +6 -2
- package/src/market-data/futures-board.ts +36 -29
- package/src/market-data/futures-contract.ts +37 -1
- package/src/market-data/hooks.tsx +33 -2
- package/src/market-data/market/change-basis.ts +11 -1
- package/src/market-data/market/header-market.ts +11 -0
- package/src/market-data/market/status.ts +40 -4
- package/src/market-data/performance.ts +127 -32
- package/src/market-data/quotes/time.ts +5 -2
- package/src/market-data/split-terms.ts +28 -0
- package/src/news/types.ts +28 -0
- package/src/notifications/app-badge.ts +2 -3
- package/src/notifications/app-notifier.ts +5 -0
- package/src/plugins/builtin/account-management/footer.ts +1 -1
- package/src/plugins/builtin/account-management/keyboard.ts +4 -0
- package/src/plugins/builtin/account-management/model.ts +1 -0
- package/src/plugins/builtin/account-management/pane.tsx +75 -7
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +12 -5
- package/src/plugins/builtin/account-management/pro-cancel.tsx +197 -0
- package/src/plugins/builtin/account-management/trial-cancel.ts +1 -1
- package/src/plugins/builtin/alerts/cli-move.ts +2 -2
- package/src/plugins/builtin/alerts/cli.ts +101 -48
- package/src/plugins/builtin/alerts/command.ts +39 -9
- package/src/plugins/builtin/alerts/constants.ts +10 -0
- package/src/plugins/builtin/alerts/earnings-listing.ts +20 -0
- package/src/plugins/builtin/alerts/event-rows.ts +9 -3
- package/src/plugins/builtin/alerts/events-pane.tsx +16 -10
- package/src/plugins/builtin/alerts/format.ts +24 -8
- package/src/plugins/builtin/alerts/headless.ts +12 -6
- package/src/plugins/builtin/alerts/index.tsx +97 -16
- package/src/plugins/builtin/alerts/move-checks.ts +7 -0
- package/src/plugins/builtin/alerts/option-contract.ts +197 -0
- package/src/plugins/builtin/alerts/pane.tsx +1 -1
- package/src/plugins/builtin/alerts/price.ts +30 -5
- package/src/plugins/builtin/alerts/pro-rules.ts +62 -0
- package/src/plugins/builtin/alerts/quotes.ts +26 -2
- package/src/plugins/builtin/alerts/research-builder.ts +5 -10
- package/src/plugins/builtin/alerts/scheduled.ts +6 -1
- package/src/plugins/builtin/alerts/types.ts +7 -0
- package/src/plugins/builtin/analytics/account-returns.ts +1 -1
- package/src/plugins/builtin/analytics/manual-value.ts +61 -0
- package/src/plugins/builtin/analytics/pane-model.ts +2 -2
- package/src/plugins/builtin/analytics/risk-book.ts +7 -7
- package/src/plugins/builtin/analytics/risk-client.ts +27 -14
- package/src/plugins/builtin/analytics/risk-headless.ts +13 -8
- package/src/plugins/builtin/analytics/risk-model.ts +92 -4
- package/src/plugins/builtin/analytics/risk-pane.tsx +85 -38
- package/src/plugins/builtin/awards/pane.tsx +1 -1
- package/src/plugins/builtin/broker-trading/orders.tsx +2 -2
- package/src/plugins/builtin/buildout/company/pane.tsx +4 -14
- package/src/plugins/builtin/catalysts/model.ts +2 -1
- package/src/plugins/builtin/central-bank-rates/model.ts +8 -2
- package/src/plugins/builtin/central-bank-rates/pane.tsx +5 -3
- package/src/plugins/builtin/chart-composer/chart-spec.ts +5 -0
- package/src/plugins/builtin/chart-composer/cli-options.ts +9 -5
- package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +2 -6
- package/src/plugins/builtin/chart-composer/headless-schema.ts +14 -10
- package/src/plugins/builtin/chart-composer/headless.ts +2 -0
- package/src/plugins/builtin/chart-composer/index.tsx +17 -5
- package/src/plugins/builtin/chart-composer/pane.tsx +19 -6
- package/src/plugins/builtin/chart-composer/viewport-labels.ts +2 -17
- package/src/plugins/builtin/chat/controller/notifications.ts +1 -0
- package/src/plugins/builtin/chat/index.tsx +0 -1
- package/src/plugins/builtin/cloud/auth-actions.tsx +11 -6
- package/src/plugins/builtin/cloud/company-picker.tsx +5 -3
- package/src/plugins/builtin/cloud/upgrade-command.ts +1 -1
- package/src/plugins/builtin/commodities-energy/index.tsx +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +10 -5
- package/src/plugins/builtin/company-kpis/latest.ts +45 -0
- package/src/plugins/builtin/company-kpis/model.ts +57 -15
- package/src/plugins/builtin/company-kpis/pane.tsx +22 -8
- package/src/plugins/builtin/composite/alt-data.ts +20 -0
- package/src/plugins/builtin/composite/application.ts +14 -0
- package/src/plugins/builtin/composite/broker.ts +12 -0
- package/src/plugins/builtin/composite/credit.ts +33 -0
- package/src/plugins/builtin/composite/crypto.ts +10 -0
- package/src/plugins/builtin/composite/earnings.ts +12 -0
- package/src/plugins/builtin/composite/filings.ts +13 -0
- package/src/plugins/builtin/composite/futures-commodities.ts +23 -0
- package/src/plugins/builtin/composite/global-markets.ts +12 -0
- package/src/plugins/builtin/composite/options-volatility.ts +23 -0
- package/src/plugins/builtin/composite/ownership.ts +23 -0
- package/src/plugins/builtin/composite/portfolio.ts +10 -0
- package/src/plugins/builtin/composite/quant.ts +15 -0
- package/src/plugins/builtin/composite/rates-macro.ts +30 -0
- package/src/plugins/builtin/composite/screeners.ts +11 -0
- package/src/plugins/builtin/composite/shared.ts +11 -0
- package/src/plugins/builtin/composite/ticker-core.ts +36 -0
- package/src/plugins/builtin/congress-trades/headless.ts +31 -3
- package/src/plugins/builtin/congress-trades/model.ts +9 -5
- package/src/plugins/builtin/correlation/index.tsx +13 -17
- package/src/plugins/builtin/correlation/matrix/model.ts +18 -0
- package/src/plugins/builtin/cot/client.ts +2 -3
- package/src/plugins/builtin/cot/headless.ts +16 -16
- package/src/plugins/builtin/cot/index.tsx +6 -6
- package/src/plugins/builtin/cot/model.ts +25 -5
- package/src/plugins/builtin/cot/pane.tsx +11 -6
- package/src/plugins/builtin/cot/series.ts +11 -8
- package/src/plugins/builtin/cpi/model.ts +15 -4
- package/src/plugins/builtin/cpi/pane.tsx +29 -7
- package/src/plugins/builtin/dividend-yield/client.ts +57 -16
- package/src/plugins/builtin/dividend-yield/headless.ts +17 -11
- package/src/plugins/builtin/dividend-yield/model.ts +4 -3
- package/src/plugins/builtin/dividend-yield/pane.tsx +22 -18
- package/src/plugins/builtin/dividend-yield/ranking.ts +1 -1
- package/src/plugins/builtin/dividend-yield/types.ts +4 -0
- package/src/plugins/builtin/dividend-yield/view.ts +23 -12
- package/src/plugins/builtin/doe/model.ts +30 -0
- package/src/plugins/builtin/doe/pane.tsx +8 -2
- package/src/plugins/builtin/earnings/board-table.ts +9 -4
- package/src/plugins/builtin/earnings/fiscal-quarter.ts +39 -0
- package/src/plugins/builtin/earnings/headless.ts +16 -6
- package/src/plugins/builtin/earnings/history-model.ts +6 -4
- package/src/plugins/builtin/earnings/history-table.ts +7 -4
- package/src/plugins/builtin/earnings-calls/calendar.tsx +4 -3
- package/src/plugins/builtin/earnings-calls/pane.tsx +8 -2
- package/src/plugins/builtin/earnings-ripple/pane.tsx +2 -2
- package/src/plugins/builtin/econ/calendar-model.ts +16 -0
- package/src/plugins/builtin/econ/index.tsx +7 -2
- package/src/plugins/builtin/equity-screener/headless.ts +4 -1
- package/src/plugins/builtin/equity-screener/model.ts +7 -6
- package/src/plugins/builtin/estimate-revisions/headless.ts +1 -1
- package/src/plugins/builtin/exposure/model.ts +10 -0
- package/src/plugins/builtin/exposure/pane.tsx +10 -3
- package/src/plugins/builtin/futures/model.ts +14 -1
- package/src/plugins/builtin/futures/series.ts +1 -8
- package/src/plugins/builtin/fx-matrix/amount.ts +15 -1
- package/src/plugins/builtin/fx-matrix/headless.ts +12 -6
- package/src/plugins/builtin/fx-matrix/index.tsx +25 -7
- package/src/plugins/builtin/fx-matrix/settings.ts +9 -4
- package/src/plugins/builtin/insider/detail.tsx +36 -7
- package/src/plugins/builtin/insider/filing-stories.ts +110 -0
- package/src/plugins/builtin/insider/headless.ts +37 -2
- package/src/plugins/builtin/insider/index.tsx +79 -10
- package/src/plugins/builtin/insider/model.ts +43 -5
- package/src/plugins/builtin/ipo-calendar/client.ts +11 -1
- package/src/plugins/builtin/ipo-calendar/model.ts +3 -7
- package/src/plugins/builtin/jobs/headless.ts +2 -1
- package/src/plugins/builtin/jobs/model.ts +6 -0
- package/src/plugins/builtin/jobs/pane.tsx +8 -3
- package/src/plugins/builtin/kelly-sizer/pane.tsx +9 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +22 -10
- package/src/plugins/builtin/mna/detail.tsx +67 -6
- package/src/plugins/builtin/mna/headless.ts +128 -13
- package/src/plugins/builtin/mna/model.ts +219 -16
- package/src/plugins/builtin/mna/pane.tsx +34 -6
- package/src/plugins/builtin/money-markets/model.ts +14 -5
- package/src/plugins/builtin/money-markets/pane.tsx +4 -3
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +118 -10
- package/src/plugins/builtin/news/wire/news/footer.ts +3 -8
- package/src/plugins/builtin/news/wire/news/story-evidence.ts +178 -0
- package/src/plugins/builtin/options/analytics.ts +1 -1
- package/src/plugins/builtin/options/view.tsx +18 -11
- package/src/plugins/builtin/options-positioning/model.ts +11 -0
- package/src/plugins/builtin/options-positioning/pane.tsx +22 -1
- package/src/plugins/builtin/options-scenario/client.ts +49 -8
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +22 -6
- package/src/plugins/builtin/options-scenario/csp-screen.ts +39 -12
- package/src/plugins/builtin/options-scenario/headless.ts +7 -3
- package/src/plugins/builtin/options-scenario/model.ts +33 -2
- package/src/plugins/builtin/options-scenario/pane.tsx +3 -4
- package/src/plugins/builtin/options-scenario/strategy-screen.ts +7 -5
- package/src/plugins/builtin/pe-band/client.ts +13 -1
- package/src/plugins/builtin/pe-band/headless.ts +2 -2
- package/src/plugins/builtin/pe-band/model.ts +63 -10
- package/src/plugins/builtin/pe-band/pane.tsx +5 -5
- package/src/plugins/builtin/perps/cascade.ts +4 -3
- package/src/plugins/builtin/perps/markets-section.tsx +5 -2
- package/src/plugins/builtin/perps/model.ts +4 -3
- package/src/plugins/builtin/portfolio-list/allocation-rows.ts +26 -7
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +66 -13
- package/src/plugins/builtin/portfolio-list/cli/render.ts +76 -33
- package/src/plugins/builtin/portfolio-list/headless.ts +69 -22
- package/src/plugins/builtin/portfolio-list/pane/data.ts +3 -3
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +29 -14
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +2 -2
- package/src/plugins/builtin/portfolio-list/table.tsx +3 -2
- package/src/plugins/builtin/relative-rotation/pane.tsx +2 -3
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +33 -14
- package/src/plugins/builtin/research/event-model.ts +43 -19
- package/src/plugins/builtin/research/headless.ts +8 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +19 -17
- package/src/plugins/builtin/research-search/index.tsx +3 -1
- package/src/plugins/builtin/scanner/denied.tsx +16 -4
- package/src/plugins/builtin/scanner/flow-pane.tsx +1 -1
- package/src/plugins/builtin/scanner/hilo-pane.tsx +1 -1
- package/src/plugins/builtin/sec/filing-display.tsx +14 -2
- package/src/plugins/builtin/sec/headless.ts +42 -4
- package/src/plugins/builtin/sec/index.tsx +21 -1
- package/src/plugins/builtin/sectors/index.tsx +6 -9
- package/src/plugins/builtin/sectors/sector-model.ts +1 -1
- package/src/plugins/builtin/shared/cloud-upgrade.ts +1 -1
- package/src/plugins/builtin/shared/earnings-report.ts +49 -5
- package/src/plugins/builtin/shared/options-pro-copy.ts +34 -0
- package/src/plugins/builtin/shared/report-freshness.ts +2 -3
- package/src/plugins/builtin/shared/statement-currency.ts +23 -0
- package/src/plugins/builtin/shared/ticker-surface.ts +1 -1
- package/src/plugins/builtin/supply-chain/client.ts +34 -9
- package/src/plugins/builtin/supply-chain/evidence.ts +3 -2
- package/src/plugins/builtin/supply-chain/flow.tsx +4 -3
- package/src/plugins/builtin/supply-chain/graph-model.ts +14 -7
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +3 -1
- package/src/plugins/builtin/supply-chain/graph.tsx +6 -3
- package/src/plugins/builtin/supply-chain/headless.ts +19 -4
- package/src/plugins/builtin/supply-chain/model.ts +50 -6
- package/src/plugins/builtin/supply-chain/pane.tsx +79 -18
- package/src/plugins/builtin/themes/headless.ts +4 -4
- package/src/plugins/builtin/themes/model.ts +11 -8
- package/src/plugins/builtin/themes/pane.tsx +2 -2
- package/src/plugins/builtin/ticker-detail/adr-pair/ah.ts +62 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +119 -20
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +51 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +25 -14
- package/src/plugins/builtin/ticker-detail/financials/model.ts +22 -32
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +7 -9
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +2 -0
- package/src/plugins/builtin/ticker-detail/headless.ts +28 -12
- package/src/plugins/builtin/ticker-detail/overview/board-lot.ts +21 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +28 -2
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +8 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +68 -13
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +5 -2
- package/src/plugins/builtin/volatility/model.ts +17 -0
- package/src/plugins/builtin/volatility/pane.tsx +16 -7
- package/src/plugins/builtin/world-indices/index.tsx +2 -0
- package/src/plugins/builtin/world-indices/table.tsx +15 -0
- package/src/plugins/builtin/world-venue-map/evidence.ts +3 -2
- package/src/plugins/builtin/world-venue-map/headless.ts +32 -18
- package/src/plugins/builtin/world-venue-map/index.ts +19 -6
- package/src/plugins/builtin/world-venue-map/layered-pane.tsx +9 -5
- package/src/plugins/builtin/world-venue-map/layers.ts +33 -11
- package/src/plugins/builtin/world-venue-map/map.tsx +12 -0
- package/src/plugins/builtin/world-venue-map/model.ts +6 -1
- package/src/plugins/builtin/world-venue-map/pane.tsx +35 -6
- package/src/plugins/builtin/world-venue-map/place.ts +119 -0
- package/src/plugins/builtin/world-venue-map/venue-header.tsx +5 -3
- package/src/plugins/catalog-browser.ts +10 -1
- package/src/plugins/catalog-data.ts +20 -0
- package/src/plugins/catalog-lazy.ts +51 -0
- package/src/plugins/catalog-ui.ts +16 -18
- package/src/plugins/host-smoke.ts +5 -2
- package/src/portfolio/allocation.ts +79 -19
- package/src/portfolio/cash-balances.ts +76 -0
- package/src/portfolio/mutations.ts +43 -8
- package/src/public/__snapshots__/public-api.test.ts.snap +1 -0
- package/src/renderers/browser/activity.ts +16 -0
- package/src/renderers/browser/app-badge-host.ts +14 -0
- package/src/renderers/browser/main.tsx +5 -0
- package/src/renderers/browser/notifications.ts +103 -0
- package/src/renderers/browser/ui-host.tsx +4 -0
- package/src/renderers/desktop/window-layouts.ts +14 -0
- package/src/renderers/dom/data-table/index.tsx +27 -4
- package/src/renderers/dom/data-table/row.tsx +2 -0
- package/src/renderers/dom/host/tabs.tsx +57 -8
- package/src/renderers/dom/styles.css +13 -5
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +4 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +22 -1
- package/src/renderers/electrobun/bun/window/native-min-size.ts +6 -1
- package/src/renderers/electrobun/shared/protocol.ts +4 -0
- package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +50 -12
- package/src/renderers/electrobun/view/http-fetch.ts +3 -2
- package/src/renderers/electrobun/view/remote/ticker-repository.ts +10 -0
- package/src/series/standalone-catalog.ts +5 -4
- package/src/series/standalone.ts +13 -7
- package/src/sources/gloomberb-cloud/index.ts +22 -9
- package/src/sources/gloomberb-cloud/news.ts +35 -0
- package/src/sources/gloomberb-cloud/perpetuals.ts +60 -3
- package/src/sources/provider-errors.ts +34 -7
- package/src/sources/provider-router/financials.ts +20 -13
- package/src/sources/provider-router/history.ts +32 -6
- package/src/sources/provider-router/index.ts +4 -0
- package/src/sources/provider-router/search.ts +1 -0
- package/src/sync/collections-contributor.ts +3 -1
- package/src/sync/config-merge.ts +10 -1
- package/src/sync/sanitize.ts +26 -2
- package/src/tickers/company-name-listing.ts +16 -2
- package/src/tickers/listing-fate.ts +12 -8
- package/src/tickers/renamed-listings.ts +43 -10
- package/src/tickers/search/home-listing.ts +28 -0
- package/src/tickers/search/index.ts +19 -7
- package/src/tickers/terminal-codes.ts +11 -1
- package/src/time-series/base-series.ts +39 -6
- package/src/time-series/chart-seed.ts +2 -2
- package/src/time-series/history-quality.ts +4 -1
- package/src/time-series/hooks.ts +2 -0
- package/src/time-series/price-comparison.ts +17 -23
- package/src/time-series/reporting.ts +1 -1
- package/src/time-series/resolution.ts +13 -0
- package/src/time-series/resolve-context.ts +6 -0
- package/src/time-series/resolve.ts +42 -3
- package/src/time-series/spec.ts +2 -2
- package/src/time-series/types.ts +3 -2
- package/src/types/data-provider.ts +11 -0
- package/src/types/financials.ts +48 -4
- package/src/types/headless.ts +1 -0
- package/src/types/issuer-listings.ts +2 -0
- package/src/types/plugin-notifications.ts +3 -0
- package/src/types/price-history.ts +6 -4
- package/src/types/ticker.ts +10 -2
- package/src/ui/host.tsx +2 -0
- package/src/utils/cli-output.ts +1 -1
- package/src/utils/declared-dividends.ts +13 -1
- package/src/utils/dividend-cash.ts +5 -1
- package/src/utils/exchange-announcements.ts +7 -2
- package/src/utils/forward-dividend.ts +4 -3
- package/src/utils/fundamentals.ts +40 -0
- package/src/utils/network-failure.ts +2 -0
- package/src/utils/price-history-integrity.ts +9 -1
- package/src/utils/remove-folder.ts +37 -0
- package/src/utils/trailing-dividend.ts +1 -1
- package/src/plugins/builtin/composite-plugins.ts +0 -285
|
@@ -10,6 +10,37 @@ export interface TableWidthColumn {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const TRAILING_COLUMN_GUTTER_WIDTH = 1;
|
|
13
|
+
const HIDDEN_COLUMNS = Symbol("hidden table columns");
|
|
14
|
+
type HiddenColumn = { id: string; label: string };
|
|
15
|
+
type WithHiddenColumns = { [HIDDEN_COLUMNS]?: readonly HiddenColumn[] };
|
|
16
|
+
|
|
17
|
+
function hiddenColumnEntries(columns: readonly TableWidthColumn[]): HiddenColumn[] {
|
|
18
|
+
return [...new Map(columns.flatMap((column: TableWidthColumn & WithHiddenColumns) => column[HIDDEN_COLUMNS] ?? [])
|
|
19
|
+
.map((column) => [column.id, column])).values()];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function hiddenTableColumns(columns: readonly TableWidthColumn[]): string[] {
|
|
23
|
+
return hiddenColumnEntries(columns).map(({ label }) => label);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function hiddenTableColumnRows(columns: readonly TableWidthColumn[], itemCount: number): number {
|
|
27
|
+
return itemCount > 0 && columns.some((column: TableWidthColumn & WithHiddenColumns) => column[HIDDEN_COLUMNS]?.length) ? 1 : 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function hiddenTableColumnText(columns: readonly TableWidthColumn[]): string | null {
|
|
31
|
+
const hidden = hiddenTableColumns(columns);
|
|
32
|
+
if (!hidden.length) return null;
|
|
33
|
+
const labels = new Map<string, number>();
|
|
34
|
+
for (const label of hidden) labels.set(label, (labels.get(label) ?? 0) + 1);
|
|
35
|
+
return `${hidden.length} hidden · ${[...labels].map(([label, count]) => count > 1 ? `${label} ×${count}` : label).join(", ")}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function markHiddenTableColumns<C extends TableWidthColumn & { id: string }>(original: readonly C[], shown: C[]): C[] {
|
|
39
|
+
const hidden = [...hiddenColumnEntries(original), ...original.filter(({ id }) => !shown.some((column) => column.id === id))
|
|
40
|
+
.map(({ id, label }) => ({ id, label: label?.trim() || id }))];
|
|
41
|
+
if (!shown[0] || !hidden.length) return shown;
|
|
42
|
+
return [Object.assign({ ...shown[0] }, { [HIDDEN_COLUMNS]: hidden }), ...shown.slice(1)];
|
|
43
|
+
}
|
|
13
44
|
const WEB_CELL_UNIT = "var(--cell-w)";
|
|
14
45
|
|
|
15
46
|
/** Space the sort indicator (" \u25b2") needs on top of the header label. */
|
|
@@ -76,7 +107,8 @@ export function fitTableCellText(text: string, width: number, align?: string, ke
|
|
|
76
107
|
return padToWidth(clipKeepingEnd(text, width, keepEnd), width, align);
|
|
77
108
|
}
|
|
78
109
|
|
|
79
|
-
|
|
110
|
+
/** `text` cut to `width` cells keeping `keepEnd` whole after the ellipsis, as a table cell's `keepEnd` cuts it. */
|
|
111
|
+
export function clipKeepingEnd(text: string, width: number, keepEnd: string | undefined): string {
|
|
80
112
|
if (!keepEnd || displayWidth(text) <= width || !text.endsWith(keepEnd)) return clipToDisplayWidth(text, width);
|
|
81
113
|
const lead = text.slice(0, -keepEnd.length);
|
|
82
114
|
const room = width - displayWidth(keepEnd);
|
|
@@ -135,7 +167,7 @@ export function dropColumnsToFit<C extends TableWidthColumn & { id: string }>(
|
|
|
135
167
|
const ids = typeof step === "string" ? [step] : step;
|
|
136
168
|
shown = shown.filter((column) => !ids.includes(column.id));
|
|
137
169
|
}
|
|
138
|
-
return shown;
|
|
170
|
+
return markHiddenTableColumns(columns, shown);
|
|
139
171
|
}
|
|
140
172
|
|
|
141
173
|
/**
|
|
@@ -12,6 +12,7 @@ import { Prose } from "./ui/prose";
|
|
|
12
12
|
import { logFailure } from "../utils/log-failure";
|
|
13
13
|
import { markPaneNoticesSeen, usePaneNoticesSeen } from "./pane-notice-seen";
|
|
14
14
|
import { withoutCryptoVenueCode } from "../utils/crypto-pair";
|
|
15
|
+
import { readableStatus } from "../utils/reason-codes";
|
|
15
16
|
|
|
16
17
|
export interface UsePaneNoticeFooterOptions {
|
|
17
18
|
registrationId: string;
|
|
@@ -19,6 +20,13 @@ export interface UsePaneNoticeFooterOptions {
|
|
|
19
20
|
focused: boolean;
|
|
20
21
|
title?: string;
|
|
21
22
|
enabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The notes a picture of the pane prints as its note line, every notice
|
|
25
|
+
* otherwise: for a pane whose footer already says some of them in other
|
|
26
|
+
* words (what its numbers leave out, as segments a capture keeps), the
|
|
27
|
+
* rest. Empty prints none; the dialog always lists every notice.
|
|
28
|
+
*/
|
|
29
|
+
captureNotes?: readonly string[];
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
function NoticeDialog({ notices, title, dismiss, dialogId }: AlertContext & {
|
|
@@ -78,14 +86,18 @@ export function usePaneNoticeFooter({
|
|
|
78
86
|
focused,
|
|
79
87
|
title: rawTitle = "Data warnings",
|
|
80
88
|
enabled = true,
|
|
89
|
+
captureNotes,
|
|
81
90
|
}: UsePaneNoticeFooterOptions): void {
|
|
82
91
|
const dialog = useDialog();
|
|
83
92
|
const dialogOpen = useDialogState((state) => state.isOpen);
|
|
84
93
|
const scopeActive = usePaneFooterScopeActive();
|
|
85
94
|
const title = t(rawTitle);
|
|
86
|
-
// Said as a reader takes it: a coin's pair without the internal code of the venue it is charted on
|
|
87
|
-
|
|
95
|
+
// Said as a reader takes it: a coin's pair without the internal code of the venue it is charted on, and a
|
|
96
|
+
// source's reason code (UPSTREAM_ERROR) as what happened.
|
|
97
|
+
const noticeKey = JSON.stringify([...new Set(notices.map((notice) => readableStatus(withoutCryptoVenueCode(notice.trim()))).filter(Boolean))]);
|
|
88
98
|
const currentNotices = useMemo<readonly string[]>(() => JSON.parse(noticeKey), [noticeKey]);
|
|
99
|
+
const capturedKey = captureNotes ? JSON.stringify(captureNotes.map((note) => readableStatus(note.trim())).filter(Boolean)) : null;
|
|
100
|
+
const capturedNotes = useMemo<readonly string[] | null>(() => (capturedKey ? JSON.parse(capturedKey) : null), [capturedKey]);
|
|
89
101
|
const active = enabled && scopeActive && currentNotices.length > 0;
|
|
90
102
|
const seen = usePaneNoticesSeen(currentNotices);
|
|
91
103
|
const openingRef = useRef(false);
|
|
@@ -128,11 +140,12 @@ export function usePaneNoticeFooter({
|
|
|
128
140
|
info: [{
|
|
129
141
|
id: "data-warnings",
|
|
130
142
|
icon: "warning",
|
|
143
|
+
notes: capturedNotes ?? currentNotices,
|
|
131
144
|
label: title,
|
|
132
145
|
title: `${title} (!)`,
|
|
133
146
|
shortcut: "!",
|
|
134
147
|
parts: [{ text: "⚠", tone: seen ? "muted" : "warning" }],
|
|
135
148
|
onPress: open,
|
|
136
149
|
}],
|
|
137
|
-
} : null, [active, open, seen, title]);
|
|
150
|
+
} : null, [active, open, seen, title, currentNotices, capturedNotes]);
|
|
138
151
|
}
|
|
@@ -2,6 +2,12 @@ import type { AppConfig } from "../../../types/config";
|
|
|
2
2
|
|
|
3
3
|
export { sanitizeLayout } from "../layout";
|
|
4
4
|
|
|
5
|
+
/** Another program's change to config.json, to fold into this program's copy. */
|
|
6
|
+
export interface ExternalConfigChange {
|
|
7
|
+
/** `config` with the change folded in, or the same object when it already holds it. */
|
|
8
|
+
apply(config: AppConfig): AppConfig;
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
export interface ConfigStoreHost {
|
|
6
12
|
getDataDir(): Promise<string | null>;
|
|
7
13
|
loadConfig(dataDir: string): Promise<AppConfig>;
|
|
@@ -10,6 +16,12 @@ export interface ConfigStoreHost {
|
|
|
10
16
|
resetAllData(dataDir: string): Promise<void>;
|
|
11
17
|
exportConfig(config: AppConfig, destPath: string): Promise<void>;
|
|
12
18
|
importConfig(dataDir: string, srcPath: string): Promise<AppConfig>;
|
|
19
|
+
/**
|
|
20
|
+
* Reports each change another program makes to the config while this one
|
|
21
|
+
* runs (a `gloom` command run beside the app). A host whose config no other
|
|
22
|
+
* program writes leaves it out.
|
|
23
|
+
*/
|
|
24
|
+
watchExternalChanges?(dataDir: string, listener: (change: ExternalConfigChange) => void): () => void;
|
|
13
25
|
}
|
|
14
26
|
|
|
15
27
|
let configuredHost: ConfigStoreHost | null = null;
|
|
@@ -61,3 +73,22 @@ export async function exportConfig(config: AppConfig, destPath: string): Promise
|
|
|
61
73
|
export async function importConfig(dataDir: string, srcPath: string): Promise<AppConfig> {
|
|
62
74
|
return (await getHost()).importConfig(dataDir, srcPath);
|
|
63
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Calls `listener` with each change another program makes to the config of
|
|
79
|
+
* `dataDir` while this one runs. The listener folds it into the app's state
|
|
80
|
+
* at once: saves already waiting are written with it.
|
|
81
|
+
*/
|
|
82
|
+
export function watchExternalConfigChanges(dataDir: string, listener: (change: ExternalConfigChange) => void): () => void {
|
|
83
|
+
let stop: (() => void) | null = null;
|
|
84
|
+
let stopped = false;
|
|
85
|
+
void getHost().then((host) => {
|
|
86
|
+
if (stopped || !host.watchExternalChanges) return;
|
|
87
|
+
stop = host.watchExternalChanges(dataDir, listener);
|
|
88
|
+
}, () => { /* Intentional ignore: a renderer without a config store has no file to watch. */ });
|
|
89
|
+
return () => {
|
|
90
|
+
stopped = true;
|
|
91
|
+
stop?.();
|
|
92
|
+
stop = null;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -11,11 +11,22 @@ import { EXTRACTED_PLUGINS } from "../../../plugins/extracted-plugins";
|
|
|
11
11
|
import { makePrivateDir, writePrivateFile } from "../../../utils/private-files";
|
|
12
12
|
import { renameIntoPlace } from "../../../utils/replace-file";
|
|
13
13
|
import { tightenProfilePermissions } from "../../profile-permissions";
|
|
14
|
+
import type { ExternalConfigChange } from "./index";
|
|
14
15
|
import type { ConfigMigrationHost } from "./migrations";
|
|
15
16
|
import {
|
|
16
17
|
normalizeConfigForSave,
|
|
17
18
|
normalizeLoadedConfig,
|
|
18
19
|
} from "./normalize";
|
|
20
|
+
import { applyProfileEdits, sameProfileJson, type ProfileJson } from "../../profile-merge";
|
|
21
|
+
import {
|
|
22
|
+
changesHeld,
|
|
23
|
+
changesSince,
|
|
24
|
+
forgetSharedFile,
|
|
25
|
+
markChangesHeld,
|
|
26
|
+
noteSharedFileRead,
|
|
27
|
+
watchSharedFile,
|
|
28
|
+
writeSharedFile,
|
|
29
|
+
} from "./shared-file";
|
|
19
30
|
|
|
20
31
|
const configLog = debugLog.createLogger("config");
|
|
21
32
|
const IN_MEMORY_DATA_DIR = ":memory:";
|
|
@@ -96,23 +107,25 @@ async function loadConfigState(dataDir: string): Promise<{ config: AppConfig; ne
|
|
|
96
107
|
const raw = await readFile(configPath, "utf-8");
|
|
97
108
|
const saved = JSON.parse(raw) as Record<string, unknown>;
|
|
98
109
|
const state = normalizeLoadedConfig(saved, dataDir, migrationHost);
|
|
110
|
+
noteSharedFileRead(configPath, raw);
|
|
99
111
|
// A config.json that names a different directory than the one it belongs
|
|
100
112
|
// to came along with a moved folder. Record where it lives now, so the next
|
|
101
113
|
// launch reads it directly instead of through the missing-path fallback.
|
|
102
114
|
const recorded = typeof saved.dataDir === "string" ? saved.dataDir : null;
|
|
103
|
-
return {
|
|
115
|
+
return {
|
|
116
|
+
config: markChangesHeld(configPath, state.config),
|
|
117
|
+
needsSave: state.needsSave || (recorded !== null && recorded !== dataDir),
|
|
118
|
+
};
|
|
104
119
|
} catch {
|
|
105
120
|
// Fresh installs have no former built-in plugins to restore. Record the
|
|
106
121
|
// current baseline so onboarding never waits for plugin network installs.
|
|
107
122
|
return {
|
|
108
|
-
config: { ...createDefaultConfig(dataDir), seededPlugins: EXTRACTED_PLUGINS.map((plugin) => plugin.id) },
|
|
123
|
+
config: markChangesHeld(configFileFor(dataDir), { ...createDefaultConfig(dataDir), seededPlugins: EXTRACTED_PLUGINS.map((plugin) => plugin.id) }),
|
|
109
124
|
needsSave: true,
|
|
110
125
|
};
|
|
111
126
|
}
|
|
112
127
|
}
|
|
113
128
|
|
|
114
|
-
/** The save in flight or queued last for each config file; it never rejects. */
|
|
115
|
-
const saveQueues = new Map<string, Promise<void>>();
|
|
116
129
|
let tempFileCounter = 0;
|
|
117
130
|
|
|
118
131
|
async function writeConfigFile(configPath: string, contents: string): Promise<void> {
|
|
@@ -133,7 +146,9 @@ async function writeConfigFile(configPath: string, contents: string): Promise<vo
|
|
|
133
146
|
/**
|
|
134
147
|
* Saves to one file run one after another in call order, so the last call is
|
|
135
148
|
* the one on disk and none is lost. A failed save rejects only its own caller
|
|
136
|
-
* and the next one still runs.
|
|
149
|
+
* and the next one still runs. What another program wrote to the file since
|
|
150
|
+
* this one last read or wrote it (a `gloom` command run beside the app) is
|
|
151
|
+
* kept: see `shared-file.ts`.
|
|
137
152
|
*/
|
|
138
153
|
export async function saveConfig(config: AppConfig): Promise<void> {
|
|
139
154
|
// `:memory:` is the data directory of a config kept in memory (tests, as for
|
|
@@ -143,13 +158,47 @@ export async function saveConfig(config: AppConfig): Promise<void> {
|
|
|
143
158
|
// Written as it was when called, however the caller's object changes while
|
|
144
159
|
// earlier saves are still running.
|
|
145
160
|
const contents = JSON.stringify(normalizeConfigForSave(config), null, 2);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
161
|
+
return writeSharedFile(configPath, contents, changesHeld(configPath, config), (output) => writeConfigFile(configPath, output));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Calls `listener` with each change another program makes to the config of
|
|
166
|
+
* `dataDir` while this one runs, as soon as it is found. The listener folds
|
|
167
|
+
* it into the app's state before anything more is written.
|
|
168
|
+
*/
|
|
169
|
+
export function watchExternalChanges(dataDir: string, listener: (change: ExternalConfigChange) => void): () => void {
|
|
170
|
+
if (dataDir === IN_MEMORY_DATA_DIR) return () => {};
|
|
171
|
+
const configPath = configFileFor(dataDir);
|
|
172
|
+
return watchSharedFile(configPath, (change) => {
|
|
173
|
+
// A copy that does not say what it holds was built before this change was found.
|
|
174
|
+
listener({ apply: (config) => foldConfigChanges(configPath, config, change.index + 1, change.index) });
|
|
151
175
|
});
|
|
152
|
-
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The top-level settings one derives from the others: a change to either takes all three. */
|
|
179
|
+
const LAYOUT_KEYS = ["layout", "layouts", "activeLayoutIndex"];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* `config` with the changes it lacks, up to the first `upTo`, folded in. What
|
|
183
|
+
* the changes leave alone keeps its object, so a pane that reads it does not
|
|
184
|
+
* redraw for another program's edit elsewhere.
|
|
185
|
+
*/
|
|
186
|
+
function foldConfigChanges(configPath: string, config: AppConfig, upTo: number, unmarked: number): AppConfig {
|
|
187
|
+
const held = changesHeld(configPath, config, unmarked);
|
|
188
|
+
if (held >= upTo) return config;
|
|
189
|
+
const saved = JSON.parse(JSON.stringify(normalizeConfigForSave(config))) as Record<string, ProfileJson>;
|
|
190
|
+
let merged = saved;
|
|
191
|
+
for (const change of changesSince(configPath, held).slice(0, upTo - held)) merged = applyProfileEdits(merged, change.edits);
|
|
192
|
+
if (merged === saved) return markChangesHeld(configPath, { ...config }, upTo);
|
|
193
|
+
const loaded = normalizeLoadedConfig(merged, config.dataDir, migrationHost).config as unknown as Record<string, unknown>;
|
|
194
|
+
const next: Record<string, unknown> = { ...config };
|
|
195
|
+
const touched = new Set(Object.keys({ ...saved, ...merged }).filter((key) => !sameProfileJson(saved[key], merged[key])));
|
|
196
|
+
if (LAYOUT_KEYS.some((key) => touched.has(key))) for (const key of LAYOUT_KEYS) touched.add(key);
|
|
197
|
+
for (const key of touched) {
|
|
198
|
+
if (Object.hasOwn(loaded, key)) next[key] = loaded[key];
|
|
199
|
+
else delete next[key];
|
|
200
|
+
}
|
|
201
|
+
return markChangesHeld(configPath, next as unknown as AppConfig, upTo);
|
|
153
202
|
}
|
|
154
203
|
|
|
155
204
|
export async function initDataDir(dataDir: string): Promise<AppConfig> {
|
|
@@ -168,6 +217,7 @@ export async function resetAllData(dataDir: string): Promise<void> {
|
|
|
168
217
|
// Settings outside the data directory (the XDG config file) go too, or the
|
|
169
218
|
// next launch would skip the setup wizard the reset promises.
|
|
170
219
|
await rm(configFileFor(dataDir), { force: true });
|
|
220
|
+
forgetSharedFile(configFileFor(dataDir));
|
|
171
221
|
}
|
|
172
222
|
|
|
173
223
|
export async function exportConfig(config: AppConfig, destPath: string): Promise<void> {
|
|
@@ -25,6 +25,7 @@ import { encodeBuiltinDisabledPluginIds, expandBuiltinPluginGroups } from "../..
|
|
|
25
25
|
import { sanitizeSavedPaneState } from "./pane-state";
|
|
26
26
|
import { isRecord } from "../../../utils/guards";
|
|
27
27
|
import { normalizeWatchlistGroups } from "../../../portfolio/watchlist-groups";
|
|
28
|
+
import { portfolioCashBalances, withPortfolioCashBalances } from "../../../portfolio/cash-balances";
|
|
28
29
|
import { normalizeStoredBaseCurrency } from "../../../utils/base-currency";
|
|
29
30
|
import { debugLog } from "../../../utils/debug-log";
|
|
30
31
|
import { DEFAULT_THEME, themes } from "../../../theme/themes";
|
|
@@ -401,8 +402,9 @@ function sanitizePortfolios(value: unknown, fallback: Portfolio[]): Portfolio[]
|
|
|
401
402
|
|
|
402
403
|
/** Cash, target weights, the import source and a fixed currency the portfolio commands write; a malformed one is dropped. */
|
|
403
404
|
function sanitizePortfolioAllocation(entry: Portfolio): Portfolio {
|
|
404
|
-
const { cash, targetWeights, importedFrom, fixedCurrency, ...portfolio } = entry;
|
|
405
|
-
|
|
405
|
+
const { cash, otherCash, targetWeights, importedFrom, fixedCurrency, ...portfolio } = entry;
|
|
406
|
+
// Each currency's balance once, the first in `cash` as an older build reads it.
|
|
407
|
+
const next: Portfolio = withPortfolioCashBalances(portfolio, portfolioCashBalances({ cash, otherCash }));
|
|
406
408
|
if (fixedCurrency === true) next.fixedCurrency = true;
|
|
407
409
|
if (isRecord(importedFrom) && importedFrom.kind === "13f"
|
|
408
410
|
&& [importedFrom.cik, importedFrom.name, importedFrom.period, importedFrom.filed].every((value) => typeof value === "string" && value)) {
|
|
@@ -414,10 +416,6 @@ function sanitizePortfolioAllocation(entry: Portfolio): Portfolio {
|
|
|
414
416
|
next.importedFrom.weights = Object.fromEntries(weights) as Record<string, number>;
|
|
415
417
|
}
|
|
416
418
|
}
|
|
417
|
-
if (isRecord(cash) && typeof cash.amount === "number" && Number.isFinite(cash.amount)
|
|
418
|
-
&& typeof cash.currency === "string" && /^[A-Z]{3}$/.test(cash.currency)) {
|
|
419
|
-
next.cash = { amount: cash.amount, currency: cash.currency };
|
|
420
|
-
}
|
|
421
419
|
if (isRecord(targetWeights)) {
|
|
422
420
|
const weights = Object.entries(targetWeights).filter((weight): weight is [string, number] =>
|
|
423
421
|
!!weight[0].trim() && typeof weight[1] === "number" && Number.isFinite(weight[1]) && weight[1] >= 0 && weight[1] <= 100);
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { constants, watch, type FSWatcher } from "fs";
|
|
2
|
+
import { open, readFile, rm, stat } from "fs/promises";
|
|
3
|
+
import { basename, dirname } from "path";
|
|
4
|
+
import { applyProfileEdits, diffProfile, type ProfileEdit, type ProfileJson } from "../../profile-merge";
|
|
5
|
+
import { debugLog } from "../../../utils/debug-log";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* config.json is shared: the app keeps it in memory and saves it as it goes,
|
|
9
|
+
* while a `gloom` command run beside it (`alerts add`, `config set`,
|
|
10
|
+
* `watchlist create`) reads, changes and writes it too. Each program that
|
|
11
|
+
* writes the file goes through here, so neither undoes the other:
|
|
12
|
+
*
|
|
13
|
+
* - what this program last read from the file or wrote to it is kept, and a
|
|
14
|
+
* file that no longer reads so was changed by another program;
|
|
15
|
+
* - that change is folded into whatever this program writes next, and handed
|
|
16
|
+
* to the program's listeners (the app folds it into its state);
|
|
17
|
+
* - a write happens under a lock file, so two programs never read the same
|
|
18
|
+
* file and then each write over the other's change.
|
|
19
|
+
*
|
|
20
|
+
* A config object records how many of those changes it already holds (on a
|
|
21
|
+
* symbol, which spreads copy and JSON leaves out). One built before the app
|
|
22
|
+
* took a change in, a save still waiting on its timer, is written with that
|
|
23
|
+
* change folded in, while one built after it is written as it is, so an edit
|
|
24
|
+
* made in the app after taking the change in is never undone by it again.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const log = debugLog.createLogger("config");
|
|
28
|
+
|
|
29
|
+
const CHANGES_HELD = Symbol.for("gloomberb.config.externalChangesHeld");
|
|
30
|
+
|
|
31
|
+
/** A lock older than this was left by a program that stopped mid-write. */
|
|
32
|
+
const LOCK_STALE_MS = 10_000;
|
|
33
|
+
/** A lock held longer than this is waited out no longer: the write goes ahead. */
|
|
34
|
+
const LOCK_WAIT_MS = 2_000;
|
|
35
|
+
const LOCK_RETRY_MS = 15;
|
|
36
|
+
/** How soon a change event is read, so one write's several events read once. */
|
|
37
|
+
const CHECK_DELAY_MS = 50;
|
|
38
|
+
/** How often the file is looked at besides its change events, which some disks never send. */
|
|
39
|
+
const POLL_MS = 3_000;
|
|
40
|
+
|
|
41
|
+
export interface SharedFileChange {
|
|
42
|
+
/** The change's place among the ones found: a config holding it has a count past this. */
|
|
43
|
+
readonly index: number;
|
|
44
|
+
readonly edits: readonly ProfileEdit[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface SharedFileState {
|
|
48
|
+
/** The file as this program last read or wrote it; null before either. */
|
|
49
|
+
known: string | null;
|
|
50
|
+
/** The changes other programs made, in the order they were found. */
|
|
51
|
+
readonly changes: SharedFileChange[];
|
|
52
|
+
readonly listeners: Set<(change: SharedFileChange) => void>;
|
|
53
|
+
/** The save in flight or queued last; it never rejects. */
|
|
54
|
+
queue: Promise<void>;
|
|
55
|
+
stopWatching: (() => void) | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const states = new Map<string, SharedFileState>();
|
|
59
|
+
|
|
60
|
+
function stateFor(path: string): SharedFileState {
|
|
61
|
+
let state = states.get(path);
|
|
62
|
+
if (!state) {
|
|
63
|
+
state = { known: null, changes: [], listeners: new Set(), queue: Promise.resolve(), stopWatching: null };
|
|
64
|
+
states.set(path, state);
|
|
65
|
+
}
|
|
66
|
+
return state;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* How many of the file's changes `value` holds: those found before it was
|
|
71
|
+
* read or took them in. A value that does not say (built from scratch, or
|
|
72
|
+
* passed through a structured clone) counts as holding `unmarked`, every
|
|
73
|
+
* change found so far unless the caller knows better.
|
|
74
|
+
*/
|
|
75
|
+
export function changesHeld(path: string, value: object, unmarked = stateFor(path).changes.length): number {
|
|
76
|
+
const held = (value as Record<symbol, unknown>)[CHANGES_HELD];
|
|
77
|
+
return typeof held === "number" ? held : unmarked;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Marks `value` as holding every change found so far, or the first `count`. */
|
|
81
|
+
export function markChangesHeld<T extends object>(path: string, value: T, count = stateFor(path).changes.length): T {
|
|
82
|
+
(value as Record<symbol, unknown>)[CHANGES_HELD] = count;
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The file was read: its first read is what later reads and writes are compared with. */
|
|
87
|
+
export function noteSharedFileRead(path: string, contents: string): void {
|
|
88
|
+
const state = stateFor(path);
|
|
89
|
+
if (state.known === null) state.known = contents;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The file is gone (a reset): the next write starts over. */
|
|
93
|
+
export function forgetSharedFile(path: string): void {
|
|
94
|
+
stateFor(path).known = null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The changes found after the first `held`, to fold into a copy built before them. */
|
|
98
|
+
export function changesSince(path: string, held: number): SharedFileChange[] {
|
|
99
|
+
return stateFor(path).changes.slice(held);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function parse(contents: string): ProfileJson | undefined {
|
|
103
|
+
try {
|
|
104
|
+
return JSON.parse(contents) as ProfileJson;
|
|
105
|
+
} catch {
|
|
106
|
+
// Intentional ignore: a file that does not parse has nothing to merge; it is written over as before.
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function readIfPresent(path: string): Promise<string | null> {
|
|
112
|
+
try {
|
|
113
|
+
return await readFile(path, "utf-8");
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if ((error as { code?: unknown } | null)?.code === "ENOENT") return null;
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Compares the file with what this program knows of it, and records what another program changed. */
|
|
121
|
+
function noteContents(path: string, state: SharedFileState, contents: string | null): void {
|
|
122
|
+
if (contents === null || contents === state.known) return;
|
|
123
|
+
const known = state.known;
|
|
124
|
+
state.known = contents;
|
|
125
|
+
if (known === null) return;
|
|
126
|
+
const before = parse(known);
|
|
127
|
+
const after = parse(contents);
|
|
128
|
+
if (before === undefined || after === undefined) return;
|
|
129
|
+
const edits = diffProfile(before, after);
|
|
130
|
+
if (edits.length === 0) return;
|
|
131
|
+
const change: SharedFileChange = { index: state.changes.length, edits };
|
|
132
|
+
state.changes.push(change);
|
|
133
|
+
log.info("config.changed.elsewhere", { edits: edits.length });
|
|
134
|
+
for (const listener of state.listeners) {
|
|
135
|
+
try {
|
|
136
|
+
listener(change);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
log.warn("config.change.listener.failed", { error: error instanceof Error ? error.message : String(error) });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function enqueue(state: SharedFileState, job: () => Promise<void>): Promise<void> {
|
|
144
|
+
const result = state.queue.then(job);
|
|
145
|
+
state.queue = result.catch(() => { /* Intentional ignore: the caller receives result; the chain only keeps later jobs running. */ });
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Writes `contents` (this program's copy, holding the first `held` changes)
|
|
151
|
+
* with every change it lacks folded in, including one found just now. Writes
|
|
152
|
+
* to one file run one after another in call order.
|
|
153
|
+
*/
|
|
154
|
+
export function writeSharedFile(
|
|
155
|
+
path: string,
|
|
156
|
+
contents: string,
|
|
157
|
+
held: number,
|
|
158
|
+
write: (contents: string) => Promise<void>,
|
|
159
|
+
): Promise<void> {
|
|
160
|
+
const state = stateFor(path);
|
|
161
|
+
return enqueue(state, () => withFileLock(path, async () => {
|
|
162
|
+
noteContents(path, state, await readIfPresent(path));
|
|
163
|
+
const output = foldChanges(contents, state.changes.slice(held));
|
|
164
|
+
await write(output);
|
|
165
|
+
state.known = output;
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function foldChanges(contents: string, changes: readonly SharedFileChange[]): string {
|
|
170
|
+
if (changes.length === 0) return contents;
|
|
171
|
+
const mine = parse(contents);
|
|
172
|
+
if (mine === undefined) return contents;
|
|
173
|
+
let merged = mine;
|
|
174
|
+
for (const change of changes) merged = applyProfileEdits(merged, change.edits);
|
|
175
|
+
return merged === mine ? contents : JSON.stringify(merged, null, 2);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Reads the file now and hands any change another program made to the listeners. */
|
|
179
|
+
function checkSharedFile(path: string): Promise<void> {
|
|
180
|
+
const state = stateFor(path);
|
|
181
|
+
return enqueue(state, async () => {
|
|
182
|
+
noteContents(path, state, await readIfPresent(path));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Calls `listener` with each change another program makes to the file,
|
|
188
|
+
* found by watching it, or at the latest when this program next writes it.
|
|
189
|
+
* A listener runs before anything else is written, and must fold the change
|
|
190
|
+
* into this program's copy before it returns.
|
|
191
|
+
*/
|
|
192
|
+
export function watchSharedFile(path: string, listener: (change: SharedFileChange) => void): () => void {
|
|
193
|
+
const state = stateFor(path);
|
|
194
|
+
state.listeners.add(listener);
|
|
195
|
+
if (!state.stopWatching) state.stopWatching = startWatching(path);
|
|
196
|
+
return () => {
|
|
197
|
+
state.listeners.delete(listener);
|
|
198
|
+
if (state.listeners.size === 0 && state.stopWatching) {
|
|
199
|
+
state.stopWatching();
|
|
200
|
+
state.stopWatching = null;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function startWatching(path: string): () => void {
|
|
206
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
207
|
+
let lastSeen: string | null = null;
|
|
208
|
+
const check = () => {
|
|
209
|
+
timer = null;
|
|
210
|
+
checkSharedFile(path).catch((error: unknown) => {
|
|
211
|
+
log.warn("config.check.failed", { error: error instanceof Error ? error.message : String(error) });
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
const soon = () => {
|
|
215
|
+
if (timer) return;
|
|
216
|
+
timer = setTimeout(check, CHECK_DELAY_MS);
|
|
217
|
+
timer.unref?.();
|
|
218
|
+
};
|
|
219
|
+
let watcher: FSWatcher | null = null;
|
|
220
|
+
try {
|
|
221
|
+
// The folder, not the file: a save replaces the file, and a watch on the old one would see nothing after.
|
|
222
|
+
// Some systems name only the temporary file a save renames into place (config.json.<n>.tmp).
|
|
223
|
+
const name = basename(path);
|
|
224
|
+
watcher = watch(dirname(path), { persistent: false }, (_event, filename) => {
|
|
225
|
+
const changed = filename?.toString();
|
|
226
|
+
if (!changed || changed === name || changed.startsWith(`${name}.`)) soon();
|
|
227
|
+
});
|
|
228
|
+
watcher.on("error", () => {
|
|
229
|
+
watcher?.close();
|
|
230
|
+
watcher = null;
|
|
231
|
+
});
|
|
232
|
+
} catch {
|
|
233
|
+
// Intentional ignore: without change events the poll below still finds a change.
|
|
234
|
+
watcher = null;
|
|
235
|
+
}
|
|
236
|
+
const poll = setInterval(() => {
|
|
237
|
+
void stat(path).then((info) => {
|
|
238
|
+
const seen = `${info.mtimeMs}:${info.size}`;
|
|
239
|
+
if (lastSeen !== null && seen !== lastSeen) soon();
|
|
240
|
+
lastSeen = seen;
|
|
241
|
+
}, () => { /* Intentional ignore: a missing file is checked again on the next tick. */ });
|
|
242
|
+
}, POLL_MS);
|
|
243
|
+
poll.unref?.();
|
|
244
|
+
return () => {
|
|
245
|
+
if (timer) clearTimeout(timer);
|
|
246
|
+
clearInterval(poll);
|
|
247
|
+
watcher?.close();
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Runs `task` holding `<path>.lock`, which every program writing the file
|
|
253
|
+
* takes, so none reads the file while another is between its own read and
|
|
254
|
+
* write. A lock left by a program that stopped is taken over once stale, and
|
|
255
|
+
* one held too long is not waited on: a save never hangs on a lock.
|
|
256
|
+
*/
|
|
257
|
+
async function withFileLock<T>(path: string, task: () => Promise<T>): Promise<T> {
|
|
258
|
+
const lockPath = `${path}.lock`;
|
|
259
|
+
const token = `${process.pid}:${Date.now()}:${Math.random().toString(36).slice(2)}`;
|
|
260
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
261
|
+
let held = false;
|
|
262
|
+
for (;;) {
|
|
263
|
+
try {
|
|
264
|
+
const handle = await open(lockPath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
|
|
265
|
+
try {
|
|
266
|
+
await handle.writeFile(token, "utf-8");
|
|
267
|
+
} finally {
|
|
268
|
+
await handle.close();
|
|
269
|
+
}
|
|
270
|
+
held = true;
|
|
271
|
+
break;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
const code = (error as { code?: unknown } | null)?.code;
|
|
274
|
+
// No folder yet, or one that refuses the lock: the write goes ahead and reports its own failure.
|
|
275
|
+
if (code !== "EEXIST") break;
|
|
276
|
+
if (await lockIsStale(lockPath)) {
|
|
277
|
+
await rm(lockPath, { force: true }).catch(() => { /* Intentional ignore: another program may have taken it over first. */ });
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (Date.now() >= deadline) {
|
|
281
|
+
log.warn("config.lock.busy", { lockPath });
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_MS));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
return await task();
|
|
289
|
+
} finally {
|
|
290
|
+
if (held) await releaseLock(lockPath, token);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function lockIsStale(lockPath: string): Promise<boolean> {
|
|
295
|
+
try {
|
|
296
|
+
return Date.now() - (await stat(lockPath)).mtimeMs > LOCK_STALE_MS;
|
|
297
|
+
} catch {
|
|
298
|
+
// Intentional ignore: a lock gone meanwhile is free; the next try takes it.
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async function releaseLock(lockPath: string, token: string): Promise<void> {
|
|
304
|
+
try {
|
|
305
|
+
if (await readFile(lockPath, "utf-8") === token) await rm(lockPath, { force: true });
|
|
306
|
+
} catch {
|
|
307
|
+
// Intentional ignore: a lock already gone, or taken over as stale, is not this write's to remove.
|
|
308
|
+
}
|
|
309
|
+
}
|