@gloom-sh/terminal 0.20.3 → 0.20.5
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/README.md +2 -0
- package/bin/gloom +9 -0
- package/bin/without-bun.cjs +98 -0
- package/package.json +3 -1
- package/src/account/auth-dialog.tsx +17 -0
- package/src/api-client/data.ts +144 -35
- package/src/api-client/fx-interventions.ts +64 -0
- package/src/api-client/index.ts +1 -0
- package/src/api-client/release-summaries.ts +21 -0
- package/src/api-client/types/econ.ts +12 -0
- package/src/api-client/yield-curves.ts +1 -1
- package/src/app/global-shortcuts.ts +4 -1
- package/src/app/keybindings/actions.ts +8 -2
- package/src/app/keybindings/config.ts +2 -1
- package/src/app/keybindings/index.ts +1 -0
- package/src/app/keybindings/labels.ts +6 -1
- package/src/app/keybindings/resolve.ts +23 -4
- package/src/app/keybindings/terminal-keys.ts +35 -0
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/ticker-open-runtime.ts +274 -67
- package/src/architecture/ui-literals-allowlist.json +1 -1
- package/src/capabilities/chart-series.ts +27 -1
- package/src/cli/commands/keybindings.ts +5 -5
- package/src/cli/commands/market.ts +154 -21
- package/src/cli/commands/news-search.ts +60 -10
- package/src/cli/commands/overview.ts +16 -1
- package/src/cli/commands/plugins.ts +27 -5
- package/src/cli/commands/remote.ts +16 -17
- package/src/cli/commands/system.ts +20 -4
- package/src/cli/commands/ticker.ts +60 -19
- package/src/cli/fx-forward.ts +25 -7
- package/src/cli/glossary.ts +19 -5
- package/src/cli/history-rows.ts +5 -3
- package/src/cli/index.ts +8 -8
- package/src/cli/known-gaps.ts +27 -1
- package/src/cli/listing-arg.ts +11 -1
- package/src/cli/name-entries.ts +5 -1
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/pane-functions/function-help.ts +5 -5
- package/src/cli/report-tables.ts +18 -6
- package/src/cli/result.ts +15 -7
- package/src/cli/types.ts +2 -0
- package/src/components/chart/composite/axis-overlays.tsx +22 -0
- package/src/components/chart/composite/composite-chart.tsx +54 -13
- package/src/components/chart/composite/event-captions.ts +109 -0
- package/src/components/chart/composite/event-guides.ts +74 -0
- package/src/components/chart/composite/rasterizer.ts +2 -0
- package/src/components/chart/composite/text-renderer.ts +2 -0
- package/src/components/chart/composite/types.ts +31 -0
- package/src/components/command-bar/layout-items/focused-pane.ts +5 -5
- package/src/components/command-bar/pane-settings.ts +2 -2
- package/src/components/command-bar/routes/root/provider-search.ts +5 -4
- package/src/components/command-bar/routes/root/results.ts +6 -2
- package/src/components/command-bar/routes/ticker-search/results.ts +51 -0
- package/src/components/command-bar/routes/ticker-search/route.ts +3 -2
- package/src/components/input-search-bar.tsx +9 -2
- package/src/components/layout/detached-pane-shell.tsx +1 -1
- package/src/components/layout/floating-pane.tsx +5 -1
- package/src/components/layout/pane/footer/index.tsx +21 -14
- package/src/components/layout/pane/footer/model.ts +6 -0
- package/src/components/layout/pane/header.tsx +2 -0
- package/src/components/layout/shell/action-menu-overlay.tsx +10 -5
- package/src/components/layout/shell/active-drag.ts +149 -105
- package/src/components/layout/shell/drag/drop-zones.ts +162 -0
- package/src/components/layout/shell/drag/index.ts +47 -218
- package/src/components/layout/shell/drag/live.ts +10 -3
- package/src/components/layout/shell/drag/overlays.tsx +182 -5
- package/src/components/layout/shell/drag/runtime.ts +29 -6
- package/src/components/layout/shell/drag/shared-edges.ts +156 -0
- package/src/components/layout/shell/index.tsx +11 -6
- package/src/components/layout/shell/menu.ts +11 -2
- package/src/components/layout/shell/native/pointer-runtime.ts +25 -0
- package/src/components/layout/shell/native/window-state.ts +2 -2
- package/src/components/layout/shell/pane/capture.ts +4 -1
- package/src/components/layout/shell/pane/layers.tsx +71 -7
- package/src/components/layout/shell/terminal-pointer-runtime.ts +18 -9
- package/src/components/layout/shell/window-mode/index.ts +8 -10
- package/src/components/layout/status-bar.tsx +6 -1
- package/src/components/layout/window-edit/mode.ts +39 -7
- package/src/components/layout/window-edit/presentation.ts +1 -1
- package/src/components/onboarding/first-run-workspace.ts +44 -2
- package/src/components/onboarding/onboarding-frame.tsx +11 -2
- package/src/components/onboarding/onboarding-keyboard.ts +20 -0
- package/src/components/onboarding/onboarding-wizard.tsx +16 -11
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +62 -1
- package/src/components/onboarding/use-onboarding-progress.ts +12 -4
- package/src/components/pane-settings-dialog/desktop.tsx +2 -2
- package/src/components/pane-settings-dialog/tui.tsx +2 -2
- package/src/components/pane-settings-dialog/value.ts +6 -0
- package/src/components/pane-settings-dialog.tsx +3 -3
- package/src/components/reader/detail-reader.tsx +4 -0
- package/src/components/ui/button.tsx +2 -0
- package/src/components/ui/choice-dialog.tsx +1 -0
- package/src/components/ui/data-table/index.tsx +4 -3
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/list-view.tsx +7 -12
- package/src/components/ui/loading.tsx +10 -3
- package/src/components/ui/menu.tsx +6 -2
- package/src/components/ui/page-stack-view.tsx +3 -0
- package/src/components/ui/pane-link-chip.tsx +269 -54
- package/src/components/ui/query-bar.tsx +2 -1
- package/src/components/ui/quote.ts +14 -1
- package/src/components/ui/tabs.tsx +97 -19
- package/src/core/state/app/layout-reducer.ts +7 -0
- package/src/core/state/app/layout.ts +44 -7
- package/src/core/state/app/state.ts +1 -1
- package/src/core/state/app/types.ts +22 -2
- package/src/data/config/layout.ts +5 -2
- package/src/docs/snapshot.json +54 -13
- package/src/i18n/es.ts +9 -8
- package/src/i18n/ja.ts +9 -8
- package/src/i18n/ko.ts +9 -8
- package/src/i18n/zh-cn.ts +9 -8
- package/src/i18n/zh-tw.ts +9 -8
- package/src/layout/pane-manager/floating-actions.ts +17 -0
- package/src/layout/pane-manager/floating-stack.ts +187 -0
- package/src/layout/pane-manager/floating.ts +4 -2
- package/src/layout/pane-manager/gridlock.ts +5 -1
- package/src/layout/pane-manager/index.ts +11 -0
- package/src/layout/pane-manager/layout-state.ts +10 -3
- package/src/market-data/depositary-pair.ts +5 -3
- package/src/market-data/futures-board.ts +46 -1
- package/src/market-data/futures-contract.ts +12 -3
- package/src/market-data/fx-interventions.ts +270 -0
- package/src/market-data/market/dated-previous-close.ts +94 -15
- package/src/market-data/market/status.ts +17 -1
- package/src/news/news-model.ts +44 -2
- package/src/plugins/builtin/alerts/cli.ts +4 -4
- package/src/plugins/builtin/alerts/format.ts +1 -2
- package/src/plugins/builtin/alerts/headless.ts +1 -2
- package/src/plugins/builtin/alerts/move-checks.ts +12 -6
- package/src/plugins/builtin/alerts/move.ts +30 -9
- package/src/plugins/builtin/alerts/pane.tsx +0 -2
- package/src/plugins/builtin/alerts/storage.ts +4 -2
- package/src/plugins/builtin/alerts/types.ts +12 -0
- package/src/plugins/builtin/analytics/risk-client.ts +10 -4
- package/src/plugins/builtin/analytics/risk-episodes.ts +5 -4
- package/src/plugins/builtin/analytics/risk-headless.ts +4 -2
- package/src/plugins/builtin/analytics/risk-sectors.ts +91 -0
- package/src/plugins/builtin/awards/index.tsx +1 -1
- package/src/plugins/builtin/buildout/index.tsx +1 -0
- package/src/plugins/builtin/catalysts/index.tsx +2 -2
- package/src/plugins/builtin/cds/headless.ts +4 -0
- package/src/plugins/builtin/changelog/index.tsx +292 -101
- package/src/plugins/builtin/changelog/versions.ts +293 -0
- package/src/plugins/builtin/chart-composer/headless.ts +2 -1
- package/src/plugins/builtin/chart-composer/index.tsx +1 -0
- package/src/plugins/builtin/chart-composer/intervention-events.ts +105 -0
- package/src/plugins/builtin/chart-composer/pane.tsx +21 -7
- package/src/plugins/builtin/chat/content/composer.tsx +5 -4
- package/src/plugins/builtin/chat/content/index.tsx +12 -2
- package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -3
- package/src/plugins/builtin/chat/content/open-targets.ts +3 -3
- package/src/plugins/builtin/chat/layout.ts +5 -2
- package/src/plugins/builtin/chat/message/pane-chip.tsx +61 -40
- package/src/plugins/builtin/chat/message/render-state.ts +2 -5
- package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
- package/src/plugins/builtin/chat/pane-links/previews.ts +51 -5
- package/src/plugins/builtin/chat/pane-links/share-card.ts +36 -0
- package/src/plugins/builtin/cloud/askg/attached-pane.tsx +10 -5
- package/src/plugins/builtin/cloud/askg/controller.ts +141 -5
- package/src/plugins/builtin/cloud/askg/executor.ts +113 -4
- package/src/plugins/builtin/cloud/askg/manifest.ts +28 -13
- package/src/plugins/builtin/cloud/askg/model.ts +14 -4
- package/src/plugins/builtin/cloud/askg/pane.tsx +70 -46
- package/src/plugins/builtin/cloud/askg/tool-display.ts +1 -0
- package/src/plugins/builtin/cloud/askg/turn-parts.tsx +70 -0
- package/src/plugins/builtin/cloud/terminal-relay/engine.ts +50 -130
- package/src/plugins/builtin/cloud/terminal-relay/policy.ts +327 -7
- package/src/plugins/builtin/cloud/terminal-relay/prompts.tsx +2 -1
- package/src/plugins/builtin/cloud/terminal-relay/redact.ts +52 -9
- package/src/plugins/builtin/commodities-energy/index.tsx +1 -3
- package/src/plugins/builtin/commodities-energy/view-state.ts +3 -0
- package/src/plugins/builtin/commodity-balances/index.tsx +1 -0
- package/src/plugins/builtin/company-attention/index.tsx +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +3 -1
- package/src/plugins/builtin/company-kpis/index.tsx +2 -2
- package/src/plugins/builtin/cot/headless.ts +14 -2
- package/src/plugins/builtin/cot/index.tsx +1 -1
- package/src/plugins/builtin/cpi/index.tsx +1 -1
- package/src/plugins/builtin/crypto-board/index.tsx +1 -0
- package/src/plugins/builtin/dividend-yield/index.tsx +1 -0
- package/src/plugins/builtin/doe/index.tsx +1 -1
- package/src/plugins/builtin/earnings/index.tsx +2 -2
- package/src/plugins/builtin/earnings-calls/headless.ts +5 -1
- package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
- package/src/plugins/builtin/econ/calendar-model.ts +74 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +3 -1
- package/src/plugins/builtin/econ/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +6 -0
- package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
- package/src/plugins/builtin/executives/index.tsx +1 -0
- package/src/plugins/builtin/filing-events/index.tsx +1 -0
- package/src/plugins/builtin/fixed-income/index.tsx +1 -0
- package/src/plugins/builtin/futures/index.tsx +25 -4
- package/src/plugins/builtin/futures/model.ts +28 -32
- package/src/plugins/builtin/futures/series.ts +4 -3
- package/src/plugins/builtin/futures/table.tsx +16 -9
- package/src/plugins/builtin/futures/use-board-terms.ts +3 -3
- package/src/plugins/builtin/futures-curve/headless.ts +3 -3
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +18 -0
- package/src/plugins/builtin/gpu/index.tsx +1 -1
- package/src/plugins/builtin/help/functions-table.tsx +1 -1
- package/src/plugins/builtin/help/index.tsx +14 -4
- package/src/plugins/builtin/help/keybindings-editor.tsx +19 -5
- package/src/plugins/builtin/holders/index.tsx +1 -0
- package/src/plugins/builtin/holders/report-header.ts +2 -2
- package/src/plugins/builtin/insider/index.tsx +1 -0
- package/src/plugins/builtin/iv-history/index.tsx +1 -1
- package/src/plugins/builtin/jobs/index.tsx +1 -0
- package/src/plugins/builtin/layout-manager/index.tsx +8 -8
- package/src/plugins/builtin/macro-day/headless.ts +27 -8
- package/src/plugins/builtin/macro-day/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +19 -3
- package/src/plugins/builtin/macro-day/pane.tsx +14 -9
- package/src/plugins/builtin/macro-day/releases.ts +25 -7
- package/src/plugins/builtin/market-valuation/index.tsx +1 -0
- package/src/plugins/builtin/market-valuation/pane.tsx +8 -0
- package/src/plugins/builtin/members/index.tsx +1 -1
- package/src/plugins/builtin/mna/index.tsx +1 -0
- package/src/plugins/builtin/news/headless.ts +2 -2
- package/src/plugins/builtin/news/index.tsx +4 -3
- package/src/plugins/builtin/news/wire/index.tsx +5 -1
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +4 -0
- package/src/plugins/builtin/news/wire/news/list-search.ts +5 -2
- package/src/plugins/builtin/options/index.tsx +1 -0
- package/src/plugins/builtin/options-positioning/index.tsx +1 -0
- package/src/plugins/builtin/pe-band/index.tsx +1 -1
- package/src/plugins/builtin/perps/markets-section.tsx +5 -2
- package/src/plugins/builtin/plugin-marketplace/pane.tsx +11 -11
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +25 -0
- package/src/plugins/builtin/portfolio-list/headless.ts +15 -6
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +3 -1
- package/src/plugins/builtin/power/index.tsx +1 -1
- package/src/plugins/builtin/realized-vol/index.tsx +1 -1
- package/src/plugins/builtin/research/event-model.ts +9 -1
- package/src/plugins/builtin/research/event-sources.ts +22 -0
- package/src/plugins/builtin/research/headless.ts +11 -5
- package/src/plugins/builtin/research/index.tsx +4 -0
- package/src/plugins/builtin/research-search/index.tsx +1 -0
- package/src/plugins/builtin/research-search/pane.tsx +8 -0
- package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
- package/src/plugins/builtin/reverse-dcf/index.tsx +1 -1
- package/src/plugins/builtin/risk-factors/index.tsx +1 -0
- package/src/plugins/builtin/scanner/headless.ts +52 -13
- package/src/plugins/builtin/seasonality/index.tsx +1 -1
- package/src/plugins/builtin/sec/index.tsx +1 -0
- package/src/plugins/builtin/series-inventory.ts +1 -1
- package/src/plugins/builtin/shared/cloud-upgrade.ts +27 -3
- package/src/plugins/builtin/shared/scanner-capture.ts +11 -3
- package/src/plugins/builtin/shared/series-list-detail.tsx +5 -0
- package/src/plugins/builtin/short-interest/index.tsx +1 -0
- package/src/plugins/builtin/social-mentions/index.tsx +1 -1
- package/src/plugins/builtin/supply-chain/index.tsx +1 -0
- package/src/plugins/builtin/thirteenf/data.ts +43 -10
- package/src/plugins/builtin/thirteenf/headless.ts +55 -11
- package/src/plugins/builtin/thirteenf/model.ts +25 -9
- package/src/plugins/builtin/thirteenf/report-notes.ts +27 -6
- package/src/plugins/builtin/thirteenf/types.ts +2 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +1 -1
- package/src/plugins/builtin/ticker-detail/financials/model.ts +12 -0
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +3 -3
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +5 -5
- package/src/plugins/builtin/ticker-detail/headless.ts +18 -13
- package/src/plugins/builtin/ticker-detail/index.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +54 -5
- package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +34 -17
- package/src/plugins/builtin/ticker-detail/pane.tsx +7 -2
- package/src/plugins/builtin/time-sales/client.ts +9 -11
- package/src/plugins/builtin/time-sales/index.tsx +1 -1
- package/src/plugins/builtin/treasury-auctions/after.ts +267 -0
- package/src/plugins/builtin/treasury-auctions/cache.ts +18 -3
- package/src/plugins/builtin/treasury-auctions/client.ts +33 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +109 -19
- package/src/plugins/builtin/treasury-auctions/index.tsx +14 -4
- package/src/plugins/builtin/treasury-auctions/model.ts +256 -28
- package/src/plugins/builtin/treasury-auctions/pane.tsx +139 -28
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +5 -2
- package/src/plugins/builtin/treasury-auctions/types.ts +7 -1
- package/src/plugins/builtin/vol-surface/index.tsx +1 -1
- package/src/plugins/builtin/world-venue-map/index.ts +1 -0
- package/src/plugins/builtin/yield-curve/curves.ts +10 -4
- package/src/plugins/builtin/yield-curve/headless.ts +6 -2
- package/src/plugins/builtin/yield-curve/index.tsx +3 -3
- package/src/plugins/builtin/yield-curve/series.ts +10 -0
- package/src/plugins/builtin/yield-curve/world.ts +3 -1
- package/src/plugins/installer.ts +45 -0
- package/src/portfolio/column-values.ts +2 -1
- package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
- package/src/public/remote.ts +7 -1
- package/src/remote/client.ts +191 -11
- package/src/remote/controller-utils.ts +13 -1
- package/src/remote/controller.ts +88 -26
- package/src/remote/endpoint.ts +24 -0
- package/src/remote/form.ts +59 -4
- package/src/remote/resources.ts +56 -19
- package/src/remote/schema.ts +22 -9
- package/src/remote/secrets.ts +12 -0
- package/src/remote/semantic-helpers.ts +29 -1
- package/src/remote/semantic-tree.tsx +44 -15
- package/src/remote/server.ts +2 -1
- package/src/remote/surface.tsx +192 -0
- package/src/remote/types.ts +5 -0
- package/src/renderers/cloudflare/worker.ts +16 -1
- package/src/renderers/dom/styles.css +40 -6
- package/src/renderers/opentui/host.tsx +6 -0
- package/src/renderers/share/layout-view.tsx +1 -1
- package/src/series/standalone.ts +2 -2
- package/src/shares/api.ts +21 -4
- package/src/shares/item.ts +73 -0
- package/src/shares/pane-item.ts +205 -0
- package/src/shares/pane.ts +4 -0
- package/src/shares/payload.ts +9 -5
- package/src/sources/gloomberb-cloud/news.ts +37 -12
- package/src/state/opening-ticker-panes.ts +47 -0
- package/src/test-support/cli-context.ts +2 -0
- package/src/test-support/preload.ts +4 -1
- package/src/tickers/instrument-kind.ts +23 -3
- package/src/tickers/renamed-listings.ts +105 -0
- package/src/tickers/search/index.ts +103 -16
- package/src/time-series/resolve.ts +2 -2
- package/src/types/config.ts +5 -0
- package/src/types/context-menu.ts +2 -0
- package/src/types/financials.ts +1 -0
- package/src/types/plugin-commands.ts +140 -0
- package/src/types/plugin-context.ts +125 -0
- package/src/types/plugin-contributions.ts +55 -0
- package/src/types/plugin-definition.ts +234 -0
- package/src/types/plugin-notifications.ts +38 -0
- package/src/types/plugin-pane-settings.ts +116 -0
- package/src/types/plugin-pane-templates.ts +160 -0
- package/src/types/plugin-panes.ts +243 -0
- package/src/types/plugin-reports.ts +35 -0
- package/src/types/plugin-shared.ts +14 -0
- package/src/types/plugin-state.ts +71 -0
- package/src/types/plugin.ts +14 -1169
- package/src/ui/index.tsx +14 -3
- package/src/updater/github-releases.ts +23 -0
- package/src/utils/central-banks.ts +86 -1
- package/src/utils/cli-output.ts +22 -9
- package/src/utils/datetime-format.ts +12 -3
- package/src/utils/depositary-receipt.ts +28 -3
- package/src/utils/fundamentals.ts +14 -0
- package/src/utils/max-drawdown.ts +97 -16
- package/src/utils/untrusted-text.ts +29 -0
package/src/ui/index.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { createElement, forwardRef, memo, useCallback, useRef, type ComponentPro
|
|
|
2
2
|
import { useForwardedScrollBoxRef, useRegisterPaneScrollBox } from "../state/pane-scroll-registry";
|
|
3
3
|
import { useUiHost, type UiHost } from "./host";
|
|
4
4
|
import { scrollBoxScrollsVertically } from "./scroll-box-axis";
|
|
5
|
-
import { useRemoteUiNode } from "../remote/semantic-tree";
|
|
5
|
+
import { useRemoteUiNode, useRemoteUiScope } from "../remote/semantic-tree";
|
|
6
6
|
import { markPure, samePureProps } from "./same-props";
|
|
7
7
|
import { assignRef } from "../react/assign-ref";
|
|
8
8
|
import {
|
|
@@ -62,14 +62,22 @@ export type {
|
|
|
62
62
|
TextareaRenderable,
|
|
63
63
|
} from "./host";
|
|
64
64
|
|
|
65
|
-
export const Box = markPure(memo(forwardRef<any, ComponentProps<UiHost["Box"]
|
|
65
|
+
export const Box = markPure(memo(forwardRef<any, ComponentProps<UiHost["Box"]> & { "data-gloom-remote-hidden"?: boolean }>(({
|
|
66
|
+
"data-gloom-remote-hidden": remoteHidden,
|
|
67
|
+
...props
|
|
68
|
+
}, ref) => {
|
|
66
69
|
const { Box: HostBox } = useUiHost();
|
|
67
70
|
const rawProps = props as Record<string, unknown>;
|
|
68
71
|
const onMouseDown = rawProps.onMouseDown as ((event?: unknown) => unknown) | undefined;
|
|
69
72
|
const onMouseUp = rawProps.onMouseUp as ((event?: unknown) => unknown) | undefined;
|
|
70
73
|
const onContextMenu = rawProps.onContextMenu as ((event?: unknown) => unknown) | undefined;
|
|
74
|
+
// A prompt's scope reaches every control drawn in it, so no assistant's UI
|
|
75
|
+
// call acts on one (terminal-relay/policy.ts).
|
|
76
|
+
const scope = useRemoteUiScope();
|
|
77
|
+
// An owner that registers the control itself (a kit Button) hides this
|
|
78
|
+
// node, which would be the same control again without its label.
|
|
71
79
|
const remoteNodeId = useRemoteUiNode(
|
|
72
|
-
onMouseDown || onMouseUp || onContextMenu
|
|
80
|
+
!remoteHidden && (onMouseDown || onMouseUp || onContextMenu)
|
|
73
81
|
? {
|
|
74
82
|
role: remotePropRole(rawProps, "box"),
|
|
75
83
|
label: remotePropLabel(rawProps),
|
|
@@ -81,6 +89,7 @@ export const Box = markPure(memo(forwardRef<any, ComponentProps<UiHost["Box"]>>(
|
|
|
81
89
|
metadata: {
|
|
82
90
|
width: rawProps.width,
|
|
83
91
|
height: rawProps.height,
|
|
92
|
+
...(scope ? { scope } : {}),
|
|
84
93
|
},
|
|
85
94
|
}
|
|
86
95
|
: null,
|
|
@@ -93,6 +102,7 @@ export const Text = markPure(memo(forwardRef<any, ComponentProps<UiHost["Text"]>
|
|
|
93
102
|
const { Text: HostText } = useUiHost();
|
|
94
103
|
const rawProps = props as Record<string, unknown>;
|
|
95
104
|
const onMouseDown = rawProps.onMouseDown as ((event?: unknown) => unknown) | undefined;
|
|
105
|
+
const scope = useRemoteUiScope();
|
|
96
106
|
const remoteNodeId = useRemoteUiNode(
|
|
97
107
|
onMouseDown
|
|
98
108
|
? {
|
|
@@ -103,6 +113,7 @@ export const Text = markPure(memo(forwardRef<any, ComponentProps<UiHost["Text"]>
|
|
|
103
113
|
actions: {
|
|
104
114
|
press: (input) => onMouseDown(remoteEvent(input)),
|
|
105
115
|
},
|
|
116
|
+
...(scope ? { metadata: { scope } } : {}),
|
|
106
117
|
}
|
|
107
118
|
: null,
|
|
108
119
|
);
|
|
@@ -140,3 +140,26 @@ export async function fetchChangelogReleases(
|
|
|
140
140
|
|
|
141
141
|
return releases.slice(0, wanted);
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The repository's CHANGELOG.md: the title and highlights of each minor
|
|
146
|
+
* version, written by hand at release time (the Changelog's version rows).
|
|
147
|
+
* Through the API rather than raw.githubusercontent.com, which the web
|
|
148
|
+
* app's content policy does not reach.
|
|
149
|
+
*/
|
|
150
|
+
const CHANGELOG_SUMMARIES_API_URL = `https://api.github.com/repos/${GLOOMBERB_REPO}/contents/CHANGELOG.md`;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* CHANGELOG.md read from GitHub itself, as written, or null when the
|
|
154
|
+
* repository has none: the Changelog's second source, after Gloom Cloud
|
|
155
|
+
* (src/api-client/release-summaries.ts).
|
|
156
|
+
*/
|
|
157
|
+
export async function fetchChangelogSummaries(signal?: AbortSignal): Promise<string | null> {
|
|
158
|
+
const response = await fetch(CHANGELOG_SUMMARIES_API_URL, {
|
|
159
|
+
signal,
|
|
160
|
+
headers: { Accept: "application/vnd.github.raw+json" },
|
|
161
|
+
});
|
|
162
|
+
if (response.status === 404) return null;
|
|
163
|
+
if (!response.ok) throw new Error(`GitHub returned ${response.status}`);
|
|
164
|
+
return response.text();
|
|
165
|
+
}
|
|
@@ -13,6 +13,10 @@ export interface CentralBank {
|
|
|
13
13
|
aliases: readonly string[];
|
|
14
14
|
/** The FRED series the board reads the row from; the other rows come from BIS. */
|
|
15
15
|
fredSeriesIds?: readonly string[];
|
|
16
|
+
/** The committee and the rate its decisions are reported by, where those are not its names: Copom, Selic. */
|
|
17
|
+
decisionWords?: readonly string[];
|
|
18
|
+
/** Names another company goes by in the news too (BCB Bancorp), never searched for its stories or matched in them. */
|
|
19
|
+
sharedNames?: readonly string[];
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -35,7 +39,7 @@ export const CENTRAL_BANKS: readonly CentralBank[] = [
|
|
|
35
39
|
{ id: "ID", place: "Indonesia", name: "Bank Indonesia", short: "Bank Indonesia", instrument: "7-day reverse repo rate", aliases: [] },
|
|
36
40
|
{ id: "KR", place: "South Korea", name: "Bank of Korea", short: "BoK", instrument: "base rate", aliases: [] },
|
|
37
41
|
{ id: "BR", place: "Brazil", name: "Central Bank of Brazil", short: "BCB", instrument: "Selic target",
|
|
38
|
-
aliases: ["Banco Central do Brasil"] },
|
|
42
|
+
aliases: ["Banco Central do Brasil"], decisionWords: ["Copom", "Selic"], sharedNames: ["BCB"] },
|
|
39
43
|
{ id: "MX", place: "Mexico", name: "Bank of Mexico", short: "Banxico", instrument: "overnight rate target",
|
|
40
44
|
aliases: ["Banco de México"] },
|
|
41
45
|
{ id: "RU", place: "Russia", name: "Bank of Russia", short: "Bank of Russia", instrument: "key rate",
|
|
@@ -69,6 +73,18 @@ export function centralBankNamed(query: string): CentralBank | null {
|
|
|
69
73
|
return CENTRAL_BANKS.find((bank) => centralBankNames(bank).some((name) => nameKey(name) === wanted)) ?? null;
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
/**
|
|
77
|
+
* The bank a single word is the short name of, in any case: what a sentence
|
|
78
|
+
* calls it or a one-word alias (ECB, BoJ, RBA, Fed, FOMC, Banxico). Never a
|
|
79
|
+
* name it shares with a company (BCB, BCB Bancorp's too). Null otherwise.
|
|
80
|
+
*/
|
|
81
|
+
export function centralBankShortNamed(word: string): CentralBank | null {
|
|
82
|
+
const wanted = nameKey(word);
|
|
83
|
+
if (!wanted || wanted.includes(" ")) return null;
|
|
84
|
+
return CENTRAL_BANKS.find((bank) => [bank.short, ...bank.aliases]
|
|
85
|
+
.some((name) => nameKey(name) === wanted && !(bank.sharedNames ?? []).some((shared) => nameKey(shared) === wanted))) ?? null;
|
|
86
|
+
}
|
|
87
|
+
|
|
72
88
|
/** Words a query puts beside a bank's name when it asks for its policy rate: "Bank of Japan rate", "ECB rate decision", "Fed funds rate". */
|
|
73
89
|
const POLICY_RATE_WORDS = new Set([
|
|
74
90
|
"rate", "rates", "policy", "interest", "decision", "decisions", "meeting", "meetings", "target", "funds",
|
|
@@ -116,3 +132,72 @@ export function centralBankCiting(fredSeriesId: string): CentralBank | null {
|
|
|
116
132
|
const wanted = fredSeriesId.trim().toUpperCase();
|
|
117
133
|
return CENTRAL_BANKS.find((bank) => bank.fredSeriesIds?.includes(wanted)) ?? null;
|
|
118
134
|
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The bank a news search names: by its names as `centralBankAskedAbout` reads
|
|
138
|
+
* them, or by the committee and rate its decisions are reported by ("copom",
|
|
139
|
+
* "copom selic", "Selic rate"). Null for anything else.
|
|
140
|
+
*/
|
|
141
|
+
export function centralBankInNews(query: string): CentralBank | null {
|
|
142
|
+
const asked = centralBankAskedAbout(query);
|
|
143
|
+
if (asked) return asked;
|
|
144
|
+
const words = nameKey(query).split(" ").filter(Boolean);
|
|
145
|
+
if (words.length === 0) return null;
|
|
146
|
+
return CENTRAL_BANKS.find((bank) => {
|
|
147
|
+
const decision = (bank.decisionWords ?? []).map((word) => nameKey(word).split(" "));
|
|
148
|
+
if (decision.length === 0) return false;
|
|
149
|
+
// Every word is one of the decision words or a word asking for the rate, and at least one is a decision word.
|
|
150
|
+
const named = words.filter((word) => decision.some((parts) => parts.includes(word)));
|
|
151
|
+
return named.length > 0 && words.every((word) => named.includes(word) || POLICY_RATE_WORDS.has(word));
|
|
152
|
+
}) ?? null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Words that ask for the newest of something without being what a story says: "latest Fed decision". */
|
|
156
|
+
const ASKING_WORDS = new Set(["current", "latest", "today"]);
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* What a news search asks of the bank besides naming it, lower case: "rate
|
|
160
|
+
* cut" of "fed rate cut", "" of "copom selic" or "Bank of Mexico". Its
|
|
161
|
+
* names, place and decision words are taken out, and the words that only ask
|
|
162
|
+
* for the newest.
|
|
163
|
+
*/
|
|
164
|
+
export function centralBankNewsTopic(bank: CentralBank, query: string): string {
|
|
165
|
+
let words = nameKey(query).split(" ").filter(Boolean);
|
|
166
|
+
const names = [`${bank.place} central bank`, ...centralBankNames(bank), bank.place, ...bank.decisionWords ?? []]
|
|
167
|
+
.map((name) => nameKey(name).split(" ")).sort((left, right) => right.length - left.length);
|
|
168
|
+
for (const name of names) {
|
|
169
|
+
for (let start = wordsIndex(words, name); start >= 0; start = wordsIndex(words, name)) {
|
|
170
|
+
words = [...words.slice(0, start), ...words.slice(start + name.length)];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return words.filter((word) => !ASKING_WORDS.has(word)).join(" ");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* What a bank's decisions are reported under, for a news search of each: its
|
|
178
|
+
* name, what a sentence calls it, its other names, "<place> central bank" and
|
|
179
|
+
* the committee and rate (Copom, Selic). Stories of the 5 Nov 2026 Banxico cut
|
|
180
|
+
* said "Bank of Mexico" or "Mexico's central bank", rarely "Banxico". A name
|
|
181
|
+
* another company shares (BCB) is left out.
|
|
182
|
+
*/
|
|
183
|
+
export function centralBankNewsQueries(bank: CentralBank): string[] {
|
|
184
|
+
const names = centralBankNames(bank).filter((name) => !bank.sharedNames?.includes(name));
|
|
185
|
+
return [...new Set([...names, `${bank.place} central bank`, ...bank.decisionWords ?? []])];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** An acronym (ECB, RBA, FOMC) is matched as a word in capitals: "the fomc" in lower case is no headline's. */
|
|
189
|
+
const ACRONYM = /^[A-Z]{2,5}$/;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Whether a story is about the bank: its title or summary names it as one of
|
|
193
|
+
* the phrases it is searched by, or as "<place>'s central bank", each as
|
|
194
|
+
* whole words. The search matches words anywhere, so "Bank of Mexico" also
|
|
195
|
+
* finds Citi Mexico's banks.
|
|
196
|
+
*/
|
|
197
|
+
export function storyNamesCentralBank(bank: CentralBank, text: string): boolean {
|
|
198
|
+
const story = ` ${nameKey(text)} `;
|
|
199
|
+
const phrases = [...centralBankNewsQueries(bank), `${bank.place}s central bank`];
|
|
200
|
+
return phrases.some((phrase) => ACRONYM.test(phrase)
|
|
201
|
+
? new RegExp(`(^|[^A-Za-z0-9])${phrase}([^A-Za-z0-9]|$)`).test(text)
|
|
202
|
+
: story.includes(` ${nameKey(phrase)} `));
|
|
203
|
+
}
|
package/src/utils/cli-output.ts
CHANGED
|
@@ -704,25 +704,31 @@ function renderTableLayout(
|
|
|
704
704
|
const renderBelow = (index: number) => (options.below?.[index] ?? []).flatMap((line) => (
|
|
705
705
|
available == null ? [line] : options.cutBelow ? [truncateDisplay(line, belowWidth)] : wrapText(line, belowWidth)
|
|
706
706
|
)).map((line) => `${belowIndent}${cliStyles.muted(line)}`.trimEnd());
|
|
707
|
+
// A moved column every row has the same value in (one currency, one feed) prints once under the table, not under each row.
|
|
708
|
+
const shared = rows.length > 1 ? stacked.filter(({ index }) => {
|
|
709
|
+
const first = rows[0]![index] ?? "";
|
|
710
|
+
return !EMPTY_CELL.test(stripAnsi(first).trim()) && rows.every((row) => (row[index] ?? "") === first);
|
|
711
|
+
}) : [];
|
|
712
|
+
const ownStacked = stacked.filter((entry) => !shared.includes(entry));
|
|
707
713
|
// Columns moved under the rows print there as `Header value`, as many to a line as fit.
|
|
708
|
-
const renderStacked = (cells: string[], rowIndex: number): string[] => {
|
|
714
|
+
const renderStacked = (entries: readonly TableEntry[], cells: string[], rowIndex: number, lineIndent: string, width: number): string[] => {
|
|
709
715
|
const lines: string[] = [];
|
|
710
716
|
let line = "";
|
|
711
|
-
for (const { column, index } of
|
|
717
|
+
for (const { column, index } of entries) {
|
|
712
718
|
const value = cells[index] ?? "";
|
|
713
719
|
if (rowIndex >= (column.stackRows ?? Infinity) || EMPTY_CELL.test(stripAnsi(value).trim())) continue;
|
|
714
720
|
const piece = `${cliStyles.muted(column.header)} ${value}`;
|
|
715
|
-
if (line && visibleLength(line) + COLUMN_GAP + visibleLength(piece) <=
|
|
721
|
+
if (line && visibleLength(line) + COLUMN_GAP + visibleLength(piece) <= width) {
|
|
716
722
|
line += `${" ".repeat(COLUMN_GAP)}${piece}`;
|
|
717
723
|
continue;
|
|
718
724
|
}
|
|
719
725
|
if (line) lines.push(line);
|
|
720
726
|
line = piece;
|
|
721
|
-
if (visibleLength(piece) <=
|
|
727
|
+
if (visibleLength(piece) <= width) continue;
|
|
722
728
|
// Too long for one line: the value wraps under itself, or under its header when the header is long too.
|
|
723
|
-
const hangs = visibleLength(column.header) + 1 <=
|
|
729
|
+
const hangs = visibleLength(column.header) + 1 <= width / 2;
|
|
724
730
|
const valueIndent = " ".repeat(hangs ? visibleLength(column.header) + 1 : COLUMN_GAP);
|
|
725
|
-
const [first = "", ...rest] = wrapText(value, Math.max(1,
|
|
731
|
+
const [first = "", ...rest] = wrapText(value, Math.max(1, width - valueIndent.length));
|
|
726
732
|
lines.push(
|
|
727
733
|
...hangs ? [`${cliStyles.muted(column.header)} ${first}`] : [cliStyles.muted(column.header), `${valueIndent}${first}`],
|
|
728
734
|
...rest.map((part) => `${valueIndent}${part}`),
|
|
@@ -730,16 +736,23 @@ function renderTableLayout(
|
|
|
730
736
|
line = "";
|
|
731
737
|
}
|
|
732
738
|
if (line) lines.push(line);
|
|
733
|
-
return lines.map((text) => `${
|
|
739
|
+
return lines.map((text) => `${lineIndent}${text}`.trimEnd());
|
|
734
740
|
};
|
|
735
|
-
|
|
741
|
+
const sharedLines = shared.length > 0 ? renderStacked(shared, rows[0]!, 0, indent, Math.max(1, available ?? 0)) : [];
|
|
742
|
+
return [
|
|
743
|
+
header,
|
|
744
|
+
...divider,
|
|
745
|
+
...rows.flatMap((row, index) => [renderRow(row), ...renderStacked(ownStacked, row, index, belowIndent, belowWidth), ...renderBelow(index)]),
|
|
746
|
+
...sharedLines,
|
|
747
|
+
].join("\n");
|
|
736
748
|
}
|
|
737
749
|
|
|
738
750
|
/**
|
|
739
751
|
* A table fitted to the terminal (or `--width`), or whole when output is
|
|
740
752
|
* piped. A table too wide never cuts a cell short, unless its column is free
|
|
741
753
|
* text marked `shrink: true`: text wraps in its cell and columns move under
|
|
742
|
-
* their rows, each value whole after its header
|
|
754
|
+
* their rows, each value whole after its header, or once under the table when
|
|
755
|
+
* every row has the same one (a currency, a feed). Of the ways that fit, the
|
|
743
756
|
* one with the fewest lines prints, the one that moves fewer columns on a tie.
|
|
744
757
|
* Plain output (`setCliPlainOverride`) has no rule under the header, words
|
|
745
758
|
* for arrows and "—" in every empty cell.
|
|
@@ -155,15 +155,24 @@ function utcMidnight(date: Date): number {
|
|
|
155
155
|
* in another year). A weekday never names a day a week or more back. With
|
|
156
156
|
* `utc`, the same in UTC, for a column whose header names the zone.
|
|
157
157
|
*/
|
|
158
|
-
export function formatFeedTime(
|
|
158
|
+
export function formatFeedTime(
|
|
159
|
+
value: DisplayDateValue,
|
|
160
|
+
now = Date.now(),
|
|
161
|
+
fallback = "-",
|
|
162
|
+
{ utc = false, dayToday = false }: {
|
|
163
|
+
utc?: boolean;
|
|
164
|
+
/** Today's time carries its weekday too ("Sat 00:47"), for a column whose other rows name theirs ("Fri 21:00"). */
|
|
165
|
+
dayToday?: boolean;
|
|
166
|
+
} = {},
|
|
167
|
+
): string {
|
|
159
168
|
const date = parseDisplayDate(value);
|
|
160
169
|
if (!date) return fallback;
|
|
161
170
|
const today = new Date(now);
|
|
162
171
|
const midnight = utc ? utcMidnight : localMidnight;
|
|
163
172
|
// Rounded, since a day with a DST change is 23 or 25 hours long.
|
|
164
173
|
const daysAgo = Math.round((midnight(today) - midnight(date)) / 86_400_000);
|
|
165
|
-
if (daysAgo === 0) return (utc ? utcClockFormatter : clockFormatter).format(date);
|
|
166
|
-
if (daysAgo
|
|
174
|
+
if (daysAgo === 0 && !dayToday) return (utc ? utcClockFormatter : clockFormatter).format(date);
|
|
175
|
+
if (daysAgo >= 0 && daysAgo < 7) return (utc ? utcWeekdayClockFormatter : weekdayClockFormatter).format(date).replace(",", "");
|
|
167
176
|
const sameYear = utc ? date.getUTCFullYear() === today.getUTCFullYear() : date.getFullYear() === today.getFullYear();
|
|
168
177
|
return formatShortDate(date, { year: sameYear ? false : "2-digit", utc });
|
|
169
178
|
}
|
|
@@ -62,9 +62,34 @@ export function sharesOutstandingInReceipts(
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/**
|
|
66
|
-
|
|
65
|
+
/**
|
|
66
|
+
* What a receipt's home line is a unit of, from how its market writes the
|
|
67
|
+
* code: a B3 code ending in 4 to 8 is a preferred share (PETR4, ITUB4) and
|
|
68
|
+
* one ending in 11 a unit; a BMV line marked CPO holds certificates
|
|
69
|
+
* (TLEVISACPO) and one marked UB, UBD or UBL units (FEMSAUBD, KOFUBL); a
|
|
70
|
+
* Korean code ending in 5, 7 or 9 is a preferred share (005935), and any
|
|
71
|
+
* other line on those three markets an ordinary share (VALE3, WALMEX). A home
|
|
72
|
+
* line elsewhere, or none, says plain shares: its code does not say its class
|
|
73
|
+
* (PFBCOLOM is Bancolombia's preferred).
|
|
74
|
+
*/
|
|
75
|
+
function homeShareClass(home: string | null | undefined): { one: string; many: string } {
|
|
76
|
+
const ticker = (home ?? "").trim().toUpperCase();
|
|
77
|
+
const [code = "", venue = ""] = ticker.includes(":") ? ticker.split(":") : [ticker.replace(/\.[A-Z]+$/, ""), ticker.match(/\.([A-Z]+)$/)?.[1] ?? ""];
|
|
78
|
+
const b3 = venue === "SA" || venue === "B3" || venue === "BVMF" || venue === "SAO" || venue === "BOVESPA";
|
|
79
|
+
const bmv = venue === "MX" || venue === "BMV";
|
|
80
|
+
const korea = venue === "KS" || venue === "KQ" || venue === "KRX" || venue === "KOSDAQ";
|
|
81
|
+
if (b3 && /^[A-Z]{4}(4|5|6|7|8)$/.test(code)) return { one: "preferred share", many: "preferred shares" };
|
|
82
|
+
if (b3 && /^[A-Z]{4}11$/.test(code)) return { one: "unit", many: "units" };
|
|
83
|
+
if (bmv && /CPO$/.test(code)) return { one: "CPO", many: "CPOs" };
|
|
84
|
+
if (bmv && /UB[DLC]?$/.test(code)) return { one: "unit", many: "units" };
|
|
85
|
+
if (korea && /^\d{5}[579]$/.test(code)) return { one: "preferred share", many: "preferred shares" };
|
|
86
|
+
return b3 || bmv || korea ? { one: "ordinary share", many: "ordinary shares" } : { one: "share", many: "shares" };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** "1 ADR = 2 shares" ("2 preferred shares" of PETR4.SA, `homeShareClass`), or null without a usable ratio. */
|
|
90
|
+
export function adrRatioText(ratio: number | null | undefined, home?: string | null): string | null {
|
|
67
91
|
if (typeof ratio !== "number" || !Number.isFinite(ratio) || ratio <= 0) return null;
|
|
68
92
|
const count = Number.isInteger(ratio) ? String(ratio) : String(Number(ratio.toPrecision(6)));
|
|
69
|
-
|
|
93
|
+
const unit = homeShareClass(home);
|
|
94
|
+
return `1 ADR = ${count} ${ratio === 1 ? unit.one : unit.many}`;
|
|
70
95
|
}
|
|
@@ -126,6 +126,20 @@ export function enterpriseValueLabel(fundamentals: Parameters<typeof enterpriseV
|
|
|
126
126
|
return status === "differs" ? "provider" : status === "withdrawn" || enterpriseValueWithdrawn(fundamentals) ? "unavailable" : undefined;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Whether a company's overview names the gap between the provider's EV and market cap + debt - cash: past 10% of
|
|
131
|
+
* the computed figure. A smaller gap (a 4.87T EV beside 5T computed) is a data detail the
|
|
132
|
+
* valuation panes (RV, the reverse DCF) still give in full, not a warning to greet a first look at the company.
|
|
133
|
+
* Any other check (withdrawn, not meaningful) is always named: it is why a figure is missing.
|
|
134
|
+
*/
|
|
135
|
+
export function enterpriseValueGapIsLarge(fundamentals: Parameters<typeof enterpriseValueCheck>[0]): boolean {
|
|
136
|
+
const check = enterpriseValueCheck(fundamentals);
|
|
137
|
+
if (check?.status !== "differs" || !finiteNumber(check.source) || !finiteNumber(check.computed) || check.computed <= 0) return true;
|
|
138
|
+
return Math.abs(check.source / check.computed - 1) > OVERVIEW_ENTERPRISE_VALUE_GAP;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const OVERVIEW_ENTERPRISE_VALUE_GAP = 0.1;
|
|
142
|
+
|
|
129
143
|
/**
|
|
130
144
|
* The reconciliation line under a labelled, withdrawn or not meaningful EV: "EV 61.75B USD (provider) vs 63.75B
|
|
131
145
|
* computed from market cap + total debt - cash (balance sheet 2026-06-30).", "EV N/M: cash and short-term investments
|
|
@@ -1,64 +1,145 @@
|
|
|
1
|
+
import { toBasisPoints } from "./basis-points";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The largest fall from a close to a later close (docs/usage.md, under `history`):
|
|
3
5
|
* the peak it fell from and the trough it reached, each with its date, the
|
|
4
6
|
* fall as a fraction of the peak, and the first later close back at the peak,
|
|
5
7
|
* if any. Read off closes, as returns are; a missing or non-positive close is
|
|
6
8
|
* passed over. The earliest of equal falls is the one named.
|
|
9
|
+
*
|
|
10
|
+
* A series in yield units (^TNX, a yield in percent) falls and rises by its
|
|
11
|
+
* level: the largest fall in percentage points, said in basis points (`bp`),
|
|
12
|
+
* and its largest rise as well (`maxRunUp`). A ratio of two yields is no
|
|
13
|
+
* move anyone reads.
|
|
7
14
|
*/
|
|
8
15
|
export interface MaxDrawdown {
|
|
9
16
|
peak: { date: string; close: number };
|
|
10
17
|
trough: { date: string; close: number };
|
|
11
18
|
/** trough / peak - 1: 0 when no close fell below an earlier one, else negative. */
|
|
12
19
|
drawdown: number;
|
|
20
|
+
/** A yield's fall, trough - peak in basis points to a tenth; absent for a price. */
|
|
21
|
+
bp?: number;
|
|
13
22
|
/** The first date after the trough whose close is back at the peak; null when none is in the series. */
|
|
14
23
|
recovered: string | null;
|
|
15
24
|
/** The last date in the series, which a fall not yet recovered is measured to. */
|
|
16
25
|
through: string;
|
|
17
26
|
}
|
|
18
27
|
|
|
28
|
+
/** A yield's largest rise from a close to a later close: the low it rose from and the high it reached. */
|
|
29
|
+
export interface MaxRunUp {
|
|
30
|
+
low: { date: string; close: number };
|
|
31
|
+
high: { date: string; close: number };
|
|
32
|
+
/** high - low in basis points, to a tenth: 0 when no close rose above an earlier one. */
|
|
33
|
+
bp: number;
|
|
34
|
+
/** The first date after the high whose close is back at the low; null when none is in the series. */
|
|
35
|
+
recovered: string | null;
|
|
36
|
+
through: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How a series moves: a price by its return, a yield in percent by its level. */
|
|
40
|
+
export type DrawdownScale = "return" | "yield";
|
|
41
|
+
|
|
19
42
|
interface ClosePoint {
|
|
20
43
|
/** An ISO date or instant; points sort by it. */
|
|
21
44
|
date: string;
|
|
22
45
|
close: number | null | undefined;
|
|
23
46
|
}
|
|
24
47
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.filter((point): point is { date: string; close: number } => typeof point.close === "number" && Number.isFinite(point.close)
|
|
48
|
+
function sortedCloses(points: readonly ClosePoint[], scale: DrawdownScale) {
|
|
49
|
+
// A yield can sit at or below zero; a price there is no close.
|
|
50
|
+
return points
|
|
51
|
+
.filter((point): point is { date: string; close: number } => typeof point.close === "number" && Number.isFinite(point.close)
|
|
52
|
+
&& (scale === "yield" || point.close > 0))
|
|
29
53
|
.toSorted((left, right) => left.date.localeCompare(right.date));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The series' max drawdown, or null with fewer than two closes. */
|
|
57
|
+
export function maxDrawdown(points: readonly ClosePoint[], scale: DrawdownScale = "return"): MaxDrawdown | null {
|
|
58
|
+
const closes = sortedCloses(points, scale);
|
|
30
59
|
if (closes.length < 2) return null;
|
|
60
|
+
const fallOf = (from: number, to: number) => scale === "yield" ? to - from : to / from - 1;
|
|
31
61
|
let peak = closes[0]!;
|
|
32
|
-
let worst = { peak, trough: peak,
|
|
62
|
+
let worst = { peak, trough: peak, fall: 0 };
|
|
33
63
|
for (const point of closes) {
|
|
34
64
|
if (point.close > peak.close) peak = point;
|
|
35
|
-
const fall =
|
|
36
|
-
if (fall < worst.
|
|
65
|
+
const fall = fallOf(peak.close, point.close);
|
|
66
|
+
if (fall < worst.fall) worst = { peak, trough: point, fall };
|
|
37
67
|
}
|
|
38
|
-
const recovered = worst.
|
|
68
|
+
const recovered = worst.fall < 0
|
|
39
69
|
? closes.find((point) => point.date > worst.trough.date && point.close >= worst.peak.close)?.date ?? null
|
|
40
70
|
: null;
|
|
41
71
|
return {
|
|
42
72
|
peak: { date: worst.peak.date, close: worst.peak.close },
|
|
43
73
|
trough: { date: worst.trough.date, close: worst.trough.close },
|
|
44
|
-
drawdown: worst.
|
|
74
|
+
drawdown: scale === "yield" ? (worst.peak.close > 0 ? worst.trough.close / worst.peak.close - 1 : 0) : worst.fall,
|
|
75
|
+
...(scale === "yield" ? { bp: toBasisPoints(worst.fall, 1) } : {}),
|
|
45
76
|
recovered,
|
|
46
77
|
through: closes.at(-1)!.date,
|
|
47
78
|
};
|
|
48
79
|
}
|
|
49
80
|
|
|
81
|
+
/** A yield series' largest rise from a close to a later close, or null with fewer than two closes. */
|
|
82
|
+
export function maxRunUp(points: readonly ClosePoint[]): MaxRunUp | null {
|
|
83
|
+
const closes = sortedCloses(points, "yield");
|
|
84
|
+
if (closes.length < 2) return null;
|
|
85
|
+
let low = closes[0]!;
|
|
86
|
+
let best = { low, high: low, rise: 0 };
|
|
87
|
+
for (const point of closes) {
|
|
88
|
+
if (point.close < low.close) low = point;
|
|
89
|
+
const rise = point.close - low.close;
|
|
90
|
+
if (rise > best.rise) best = { low, high: point, rise };
|
|
91
|
+
}
|
|
92
|
+
const recovered = best.rise > 0
|
|
93
|
+
? closes.find((point) => point.date > best.high.date && point.close <= best.low.close)?.date ?? null
|
|
94
|
+
: null;
|
|
95
|
+
return {
|
|
96
|
+
low: { date: best.low.date, close: best.low.close },
|
|
97
|
+
high: { date: best.high.date, close: best.high.close },
|
|
98
|
+
bp: toBasisPoints(best.rise, 1),
|
|
99
|
+
recovered,
|
|
100
|
+
through: closes.at(-1)!.date,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface MoveTextOptions { basis: string; price: (value: number) => string; date?: (text: string) => string }
|
|
105
|
+
|
|
106
|
+
/** Whole basis points, signed; a move that rounds to nothing is still a move, which 0bp would hide. */
|
|
107
|
+
function bpText(bp: number): string {
|
|
108
|
+
const whole = Math.round(bp);
|
|
109
|
+
if (whole === 0) return bp === 0 ? "0bp" : "under 1bp";
|
|
110
|
+
return `${whole > 0 ? "+" : ""}${whole}bp`;
|
|
111
|
+
}
|
|
112
|
+
|
|
50
113
|
/**
|
|
51
114
|
* The report line: `Max drawdown -69.6% (daily closes): peak 53.25 on 2007-05-30, trough 16.19 on 2009-03-09,
|
|
52
|
-
* not back to the peak by 2009-12-31
|
|
115
|
+
* not back to the peak by 2009-12-31`; a yield's fall in bp: `Max drawdown -16bp (daily closes): ...`.
|
|
116
|
+
* `price` and `date` draw a close and a date as the table does.
|
|
53
117
|
*/
|
|
54
|
-
export function maxDrawdownText(
|
|
55
|
-
value: MaxDrawdown,
|
|
56
|
-
{ basis, price, date = (text) => text.slice(0, 10) }: { basis: string; price: (value: number) => string; date?: (text: string) => string },
|
|
57
|
-
): string {
|
|
118
|
+
export function maxDrawdownText(value: MaxDrawdown, { basis, price, date = (text) => text.slice(0, 10) }: MoveTextOptions): string {
|
|
58
119
|
const percent = (value.drawdown * 100).toFixed(1);
|
|
59
120
|
// A fall that rounds to nothing is still a fall, which -0.0% would hide.
|
|
60
|
-
const
|
|
61
|
-
|
|
121
|
+
const size = value.bp != null ? bpText(value.bp) : percent === "-0.0" ? "under 0.1%" : `${percent}%`;
|
|
122
|
+
const head = `Max drawdown ${size} (${basis})`;
|
|
123
|
+
if (value.peak.date === value.trough.date) return `${head}: no close fell below an earlier one`;
|
|
62
124
|
const back = value.recovered ? `back to the peak on ${date(value.recovered)}` : `not back to the peak by ${date(value.through)}`;
|
|
63
125
|
return `${head}: peak ${price(value.peak.close)} on ${date(value.peak.date)}, trough ${price(value.trough.close)} on ${date(value.trough.date)}, ${back}`;
|
|
64
126
|
}
|
|
127
|
+
|
|
128
|
+
/** `Max run-up +45bp (daily closes): low 3.998 on 2025-11-26, high 4.448 on 2026-01-14, not back to the low by 2026-02-02`. */
|
|
129
|
+
export function maxRunUpText(value: MaxRunUp, { basis, price, date = (text) => text.slice(0, 10) }: MoveTextOptions): string {
|
|
130
|
+
const head = `Max run-up ${bpText(value.bp)} (${basis})`;
|
|
131
|
+
if (value.low.date === value.high.date) return `${head}: no close rose above an earlier one`;
|
|
132
|
+
const back = value.recovered ? `back to the low on ${date(value.recovered)}` : `not back to the low by ${date(value.through)}`;
|
|
133
|
+
return `${head}: low ${price(value.low.close)} on ${date(value.low.date)}, high ${price(value.high.close)} on ${date(value.high.date)}, ${back}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A series' largest fall, and a yield's largest rise as well, with the lines a report says them in. */
|
|
137
|
+
export function closeMoves(points: readonly ClosePoint[], scale: DrawdownScale, text: MoveTextOptions): {
|
|
138
|
+
drawdown: MaxDrawdown | null;
|
|
139
|
+
runUp: MaxRunUp | null;
|
|
140
|
+
lines: string[];
|
|
141
|
+
} {
|
|
142
|
+
const drawdown = maxDrawdown(points, scale);
|
|
143
|
+
const runUp = scale === "yield" ? maxRunUp(points) : null;
|
|
144
|
+
return { drawdown, runUp, lines: [...drawdown ? [maxDrawdownText(drawdown, text)] : [], ...runUp ? [maxRunUpText(runUp, text)] : []] };
|
|
145
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal escape sequences: a CSI (`ESC [` or its one-byte C1 form) to its
|
|
3
|
+
* final byte, an OSC, DCS, SOS, PM or APC string to its BEL or ST (or the
|
|
4
|
+
* end), and the two-byte escapes.
|
|
5
|
+
*/
|
|
6
|
+
const ESCAPE_SEQUENCE =
|
|
7
|
+
/(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]|(?:\u001b[\]PX^_]|[\u0090\u0098\u009d-\u009f])[^\u0007\u001b\u009c]*(?:\u0007|\u001b\\|\u009c)?|\u001b[ -/]*[0-~]/g;
|
|
8
|
+
/** Marks that turn, embed or hide text without showing themselves: bidi controls and zero-width characters. */
|
|
9
|
+
const INVISIBLE = /[\u061c\u200b-\u200f\u202a-\u202e\u2060-\u2064\u2066-\u2069\ufeff]/g;
|
|
10
|
+
/** Half of a broken surrogate pair, which no font draws and Postgres does not store. */
|
|
11
|
+
const LONE_SURROGATE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
12
|
+
/** C0 and C1 controls: a line, a tab, a bell, what a terminal takes as a command. */
|
|
13
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Text another person's app wrote (a shared pane's item, a share's title), as
|
|
17
|
+
* one line that draws as what it says: no terminal escape sequence, control
|
|
18
|
+
* character, bidi control or zero-width character, and no broken surrogate
|
|
19
|
+
* pair. The share service keeps an item's text to the same rule.
|
|
20
|
+
*/
|
|
21
|
+
export function plainUntrustedLine(value: string): string {
|
|
22
|
+
return value
|
|
23
|
+
.replace(ESCAPE_SEQUENCE, "")
|
|
24
|
+
.replace(INVISIBLE, "")
|
|
25
|
+
.replace(LONE_SURROGATE, "")
|
|
26
|
+
.replace(CONTROL, " ")
|
|
27
|
+
.replace(/\s+/g, " ")
|
|
28
|
+
.trim();
|
|
29
|
+
}
|