@gloom-sh/terminal 0.19.6 → 0.20.1
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/LICENSE +0 -4
- package/package.json +6 -5
- package/patches/electrobun-devkit@2.0.5.patch +408 -0
- package/src/api-client/bond-trades.ts +59 -0
- package/src/api-client/crypto-markets.ts +20 -2
- package/src/api-client/data.ts +21 -0
- package/src/api-client/fund-facts.ts +23 -1
- package/src/api-client/index.ts +2 -0
- package/src/api-client/types/account.ts +86 -0
- package/src/api-client/types/assist.ts +32 -0
- package/src/api-client/types/auth.ts +63 -0
- package/src/api-client/types/billing.ts +54 -0
- package/src/api-client/types/chat.ts +180 -0
- package/src/api-client/types/congress.ts +107 -0
- package/src/api-client/types/credit.ts +110 -0
- package/src/api-client/types/econ.ts +158 -0
- package/src/api-client/types/equity-diagnostic.ts +73 -0
- package/src/api-client/types/filings-and-calls.ts +356 -0
- package/src/api-client/types/index.ts +25 -0
- package/src/api-client/types/jobs.ts +147 -0
- package/src/api-client/types/market.ts +122 -0
- package/src/api-client/types/news.ts +91 -0
- package/src/api-client/types/notes-and-theses.ts +172 -0
- package/src/api-client/types/quotes.ts +28 -0
- package/src/api-client/types/scanners.ts +125 -0
- package/src/api-client/types/screener.ts +65 -0
- package/src/api-client/types/search.ts +107 -0
- package/src/api-client/types/sync.ts +14 -0
- package/src/api-client/types/team-collections.ts +43 -0
- package/src/api-client/types/team-views.ts +32 -0
- package/src/api-client/types/teams.ts +135 -0
- package/src/api-client/types/ticker-data.ts +57 -0
- package/src/api-client/types/tweets.ts +59 -0
- package/src/api-client/types/world-venues.ts +23 -0
- package/src/app/runtime/desktop-deeplink.ts +41 -6
- package/src/app/runtime/plugin-seed.ts +119 -0
- package/src/app/runtime/startup.ts +45 -9
- package/src/app/star-prompt/status-line.tsx +1 -1
- package/src/app.tsx +2 -7
- package/src/architecture/ui-tokens-allowlist.json +0 -8
- package/src/cli/board-coins.ts +38 -5
- package/src/cli/commands/crypto-hints.ts +8 -1
- package/src/cli/commands/market.ts +29 -26
- package/src/cli/commands/overview.ts +13 -6
- package/src/cli/commands/ticker.ts +78 -18
- package/src/cli/company-name-hint.ts +19 -0
- package/src/cli/desktop-pane-shot-browser.ts +69 -3
- package/src/cli/entry.ts +10 -4
- package/src/cli/glossary.ts +25 -0
- package/src/cli/helpers.ts +4 -2
- package/src/cli/not-a-ticker.ts +26 -1
- package/src/cli/pane-functions/catalog.ts +3 -1
- package/src/cli/pane-functions/freshness.ts +45 -29
- package/src/cli/pane-functions/market-session.ts +14 -5
- package/src/cli/restore-plugins.ts +164 -51
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +11 -2
- package/src/components/chart-table/header.tsx +10 -1
- package/src/components/chart-table/layout.ts +14 -5
- package/src/components/command-bar/panel/index.tsx +13 -0
- package/src/components/command-bar/panel/layout.ts +7 -0
- package/src/components/command-bar/panel/runtime.ts +1 -0
- package/src/components/command-bar/panel/types.ts +2 -0
- package/src/components/data-table/export.ts +4 -1
- package/src/components/layout/detached-pane-shell.tsx +10 -37
- package/src/components/layout/double-escape-close.ts +90 -0
- package/src/components/layout/header.tsx +3 -2
- package/src/components/layout/market-summary.ts +6 -3
- package/src/components/layout/pane/footer/index.tsx +2 -6
- package/src/components/layout/pane/footer/model.ts +6 -12
- package/src/components/layout/shell/active-drag.ts +53 -11
- package/src/components/layout/shell/drag/magnets.ts +128 -19
- package/src/components/layout/shell/pane/actions.ts +6 -2
- package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
- package/src/components/layout/status-bar.tsx +4 -78
- package/src/components/layout/status-widget-space.ts +5 -5
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +1 -1
- package/src/components/ui/data-table/index.tsx +5 -1
- package/src/components/ui/data-table/render-cell.ts +19 -0
- package/src/components/ui/delayed-mark.tsx +59 -7
- package/src/components/ui/icon.tsx +1 -8
- package/src/components/ui/menu.tsx +6 -1
- package/src/i18n/es.ts +6 -3
- package/src/i18n/ja.ts +6 -3
- package/src/i18n/ko.ts +6 -3
- package/src/i18n/zh-cn.ts +6 -3
- package/src/i18n/zh-tw.ts +6 -3
- package/src/market-data/fund-facts.ts +7 -1
- package/src/market-data/market/change-basis.ts +20 -0
- package/src/market-data/market/format.ts +62 -2
- package/src/market-data/market/futures-week.ts +3 -1
- package/src/plugins/builtin/chart-composer/headless.ts +57 -17
- package/src/plugins/builtin/chart-composer/session-range.ts +82 -3
- package/src/plugins/builtin/chat/content/composer.tsx +21 -27
- package/src/plugins/builtin/chat/content/index.tsx +31 -3
- package/src/plugins/builtin/chat/content/shortcuts.ts +4 -2
- package/src/plugins/builtin/chat/content/snapshot.ts +0 -3
- package/src/plugins/builtin/cloud/auth-actions.tsx +51 -23
- package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +3 -3
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +32 -25
- package/src/plugins/builtin/congress-trades/model.ts +2 -1
- package/src/plugins/builtin/congress-trades/pane.tsx +3 -0
- package/src/plugins/builtin/correlation/compute.ts +8 -2
- package/src/plugins/builtin/correlation/headless.ts +10 -9
- package/src/plugins/builtin/correlation/history.ts +30 -0
- package/src/plugins/builtin/correlation/matrix/model.ts +10 -10
- package/src/plugins/builtin/correlation/relationship/model.ts +3 -6
- package/src/plugins/builtin/correlation/relationship/pane.tsx +1 -2
- package/src/plugins/builtin/crypto-board/client.ts +6 -1
- package/src/plugins/builtin/crypto-board/defi-view.tsx +12 -1
- package/src/plugins/builtin/crypto-board/defi.ts +44 -7
- package/src/plugins/builtin/crypto-board/headless.ts +83 -12
- package/src/plugins/builtin/crypto-board/model.ts +30 -6
- package/src/plugins/builtin/crypto-board/pane.tsx +13 -2
- package/src/plugins/builtin/custom-view/index.tsx +1 -1
- package/src/plugins/builtin/custom-view/loader.ts +85 -8
- package/src/plugins/builtin/custom-view/view-spec.ts +28 -0
- package/src/plugins/builtin/equity-screener/criterion-editor.tsx +13 -4
- package/src/plugins/builtin/equity-screener/headless.ts +33 -1
- package/src/plugins/builtin/equity-screener/model.ts +58 -15
- package/src/plugins/builtin/equity-screener/pane.tsx +36 -6
- package/src/plugins/builtin/executives/format.ts +5 -4
- package/src/plugins/builtin/executives/pane.tsx +1 -1
- package/src/plugins/builtin/help/index.tsx +55 -1
- package/src/plugins/builtin/insider/model.ts +30 -2
- package/src/plugins/builtin/jobs/model.ts +2 -2
- package/src/plugins/builtin/mna/model.ts +2 -2
- package/src/plugins/builtin/notes/files.ts +2 -0
- package/src/plugins/builtin/notes/owner.tsx +20 -1
- package/src/plugins/builtin/notes/quick-notes-pane.tsx +22 -4
- package/src/plugins/builtin/notes/store.ts +6 -1
- package/src/plugins/builtin/perps/headless.ts +8 -2
- package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
- package/src/plugins/builtin/risk-factors/index.tsx +2 -28
- package/src/plugins/builtin/risk-factors/lock-note.ts +58 -0
- package/src/plugins/builtin/risk-factors/pane.tsx +10 -3
- package/src/plugins/builtin/scanner/hilo-model.ts +4 -3
- package/src/plugins/builtin/sec/fund-facts.ts +45 -11
- package/src/plugins/builtin/sec/headless.ts +30 -1
- package/src/plugins/builtin/sec/index.tsx +26 -5
- package/src/plugins/builtin/series-inventory.ts +1 -0
- package/src/plugins/builtin/shared/earnings-report.ts +7 -2
- package/src/plugins/builtin/shared/pro-lock-note.ts +5 -1
- package/src/plugins/builtin/shared/use-quote-board.ts +85 -46
- package/src/plugins/builtin/short-interest/headless.ts +1 -1
- package/src/plugins/builtin/short-interest/model.ts +15 -6
- package/src/plugins/builtin/short-interest/types.ts +2 -0
- package/src/plugins/builtin/thirteenf/overlap-pane.tsx +3 -0
- package/src/plugins/builtin/thirteenf/pane.tsx +3 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +19 -9
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
- package/src/plugins/builtin/time-sales/headless.ts +23 -7
- package/src/plugins/builtin/time-sales/index.tsx +2 -2
- package/src/plugins/builtin/trace-bonds/detail.tsx +198 -0
- package/src/plugins/builtin/trace-bonds/headless.ts +62 -4
- package/src/plugins/builtin/trace-bonds/history.ts +155 -0
- package/src/plugins/builtin/trace-bonds/pane.tsx +64 -5
- package/src/plugins/extracted-plugins.ts +49 -24
- package/src/plugins/installer.ts +234 -32
- package/src/plugins/plugin-names.ts +11 -2
- package/src/plugins/running-installs.ts +34 -0
- package/src/plugins/seed-progress.ts +72 -0
- package/src/remote/controller.ts +9 -2
- package/src/remote/schema.ts +2 -1
- package/src/renderers/cloudflare/http-proxy.ts +67 -8
- package/src/renderers/cloudflare/proxy-session.ts +1 -1
- package/src/renderers/cloudflare/worker.ts +29 -2
- package/src/renderers/dom/desktop/icons.tsx +0 -2
- package/src/renderers/dom/styles.css +0 -3
- package/src/renderers/electrobun/bun/desktop/backend.ts +14 -0
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +14 -7
- package/src/renderers/electrobun/bun/desktop/initialization.ts +24 -14
- package/src/renderers/electrobun/bun/desktop/install-records.ts +59 -0
- package/src/renderers/electrobun/bun/desktop/installer-folder.ts +208 -592
- package/src/renderers/electrobun/bun/desktop/macos-objc.ts +14 -0
- package/src/renderers/electrobun/bun/desktop/update.ts +1 -1
- package/src/renderers/electrobun/bun/index.ts +24 -13
- package/src/renderers/electrobun/bun/window/context-menu-thread.ts +84 -0
- package/src/renderers/electrobun/bun/window/create.ts +23 -3
- package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +4 -4
- package/src/renderers/electrobun/bun/window/events.ts +4 -4
- package/src/renderers/electrobun/bun/window/frame.ts +2 -1
- package/src/renderers/electrobun/bun/window/native-call-thread.ts +224 -0
- package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
- package/src/renderers/electrobun/bun/window/native-timing.ts +10 -0
- package/src/renderers/electrobun/bun/window/script-for-webview.ts +15 -0
- package/src/renderers/electrobun/bun/window/webview-script-thread.ts +82 -0
- package/src/renderers/electrobun/shared/protocol.ts +13 -2
- package/src/renderers/electrobun/view/backend-rpc.ts +8 -1
- package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +1 -1
- package/src/renderers/electrobun/view/main.tsx +4 -3
- package/src/renderers/opentui/start.tsx +3 -0
- package/src/sources/gloomberb-cloud/index.ts +5 -7
- package/src/sources/provider-router/batches.ts +18 -3
- package/src/sources/provider-router/financials.ts +18 -4
- package/src/telemetry/stall-reports.ts +21 -4
- package/src/types/data-provider.ts +14 -0
- package/src/types/financials.ts +15 -3
- package/src/types/headless.ts +2 -0
- package/src/utils/double-escape-close.ts +38 -16
- package/src/utils/format.ts +23 -3
- package/src/utils/main-thread-stall.ts +21 -5
- package/src/utils/perf-marks.ts +88 -9
- package/src/utils/price-earnings.ts +18 -0
- package/src/utils/reported-money.ts +9 -2
- package/src/utils/sec.ts +34 -3
- package/patches/electrobun@1.18.1.patch +0 -633
- package/src/api-client/types.ts +0 -2441
- package/src/plugins/seed-notice.ts +0 -20
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { ApiRequestError } from "../../../api-client/errors";
|
|
2
|
+
import {
|
|
3
|
+
BOND_HISTORY_MAX_DAYS,
|
|
4
|
+
type StoredBondDay,
|
|
5
|
+
type StoredBondPayload,
|
|
6
|
+
type StoredBondPrint,
|
|
7
|
+
} from "../../../api-client/bond-trades";
|
|
8
|
+
import type { apiClient } from "../../../api-client";
|
|
9
|
+
import { signalWithTimeout } from "../../../utils/async-deadline";
|
|
10
|
+
import { formatCompact, MISSING_VALUE } from "../../../utils/format";
|
|
11
|
+
import { zonedDateKey } from "../../../utils/zoned-date-time";
|
|
12
|
+
import type { BondQuery } from "./client";
|
|
13
|
+
import type { TimeSeriesPoint } from "../../../time-series/types";
|
|
14
|
+
|
|
15
|
+
const TAPE_TIME_ZONE = "America/New_York";
|
|
16
|
+
const DAY_MS = 86_400_000;
|
|
17
|
+
/** How long a ticker's lookup waits for its bonds to be kept. */
|
|
18
|
+
const ISSUER_KEEP_TIMEOUT_MS = 5_000;
|
|
19
|
+
/** Prints a history read lists, newest first. */
|
|
20
|
+
const STORED_PRINTS_LIMIT = 200;
|
|
21
|
+
|
|
22
|
+
export type StoredBondClient = Pick<typeof apiClient, "getCloudStoredBond" | "getCloudStoredIssuerBonds">;
|
|
23
|
+
|
|
24
|
+
/** How far back the daily closes reach: their own range, at most the 1,100 days a read takes. */
|
|
25
|
+
export const HISTORY_RANGES = [
|
|
26
|
+
{ value: "1M", days: 31 },
|
|
27
|
+
{ value: "3M", days: 92 },
|
|
28
|
+
{ value: "1Y", days: 366 },
|
|
29
|
+
{ value: "3Y", days: BOND_HISTORY_MAX_DAYS },
|
|
30
|
+
] as const;
|
|
31
|
+
export type HistoryRange = (typeof HISTORY_RANGES)[number]["value"];
|
|
32
|
+
|
|
33
|
+
/** The days a read asks for: `days` up to today in New York, the tape's calendar. */
|
|
34
|
+
function storedHistoryWindow(now = Date.now(), days: number = BOND_HISTORY_MAX_DAYS): { from: string; to: string } {
|
|
35
|
+
const to = zonedDateKey(now, TAPE_TIME_ZONE);
|
|
36
|
+
const from = new Date(Date.parse(`${to}T00:00:00Z`) - (Math.min(days, BOND_HISTORY_MAX_DAYS) - 1) * DAY_MS)
|
|
37
|
+
.toISOString().slice(0, 10);
|
|
38
|
+
return { from, to };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Since when a bond's prints are held: `Kept since 2023-11-03.`, and while
|
|
43
|
+
* the source's earlier prints are still to be read, that they are. Null
|
|
44
|
+
* before any day was read.
|
|
45
|
+
*/
|
|
46
|
+
export function keptSinceText(payload: Pick<StoredBondPayload, "keptSince" | "backfillPending">): string | null {
|
|
47
|
+
if (!payload.keptSince) return null;
|
|
48
|
+
return payload.backfillPending
|
|
49
|
+
? `Kept since ${payload.keptSince}; earlier prints are still being read.`
|
|
50
|
+
: `Kept since ${payload.keptSince}.`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Trades and corrections no cancel names: the prints a history lists. A cancel and what it cancelled say nothing about the price. */
|
|
54
|
+
export function standingPrints(prints: readonly StoredBondPrint[]): StoredBondPrint[] {
|
|
55
|
+
return prints.filter((print) => print.status !== "cancel" && !print.cancelled);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Days with a price, oldest first: what the chart draws. */
|
|
59
|
+
export function pricedDays(days: readonly StoredBondDay[]): StoredBondDay[] {
|
|
60
|
+
return days.filter((day) => day.price != null);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Three weeks without a sale breaks the line instead of drawing prices nobody paid. */
|
|
64
|
+
const CHART_GAP_MS = 21 * DAY_MS;
|
|
65
|
+
|
|
66
|
+
/** The daily closes as the chart's points, oldest first, with a break across a long gap between sales. */
|
|
67
|
+
export function bondPricePoints(days: readonly StoredBondDay[]): TimeSeriesPoint[] {
|
|
68
|
+
const points: TimeSeriesPoint[] = [];
|
|
69
|
+
let previous: number | null = null;
|
|
70
|
+
for (const day of pricedDays(days)) {
|
|
71
|
+
const time = Date.parse(`${day.date}T00:00:00Z`);
|
|
72
|
+
if (!Number.isFinite(time)) continue;
|
|
73
|
+
if (previous !== null && time - previous > CHART_GAP_MS) {
|
|
74
|
+
const gap = new Date(previous + DAY_MS);
|
|
75
|
+
points.push({ date: gap, observedAt: gap, value: null });
|
|
76
|
+
}
|
|
77
|
+
const date = new Date(time);
|
|
78
|
+
points.push({ date, observedAt: date, value: day.price });
|
|
79
|
+
previous = time;
|
|
80
|
+
}
|
|
81
|
+
return points;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Par amount as published: `250K`, `1M+` where only a floor is published. */
|
|
85
|
+
export function formatPrintSize(print: Pick<StoredBondPrint, "quantity" | "quantityCapped">): string {
|
|
86
|
+
if (print.quantity == null) return MISSING_VALUE;
|
|
87
|
+
return `${formatCompact(print.quantity)}${print.quantityCapped ? "+" : ""}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The side the reporting dealer took. */
|
|
91
|
+
export function formatPrintSide(side: StoredBondPrint["side"]): string {
|
|
92
|
+
return side === "buy" ? "Buy" : side === "sell" ? "Sell" : MISSING_VALUE;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** What a kept history says to an account without Gloom Pro. */
|
|
96
|
+
export const PRO_HISTORY_TEXT = "Kept price history needs Gloom Pro.";
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Why a kept history could not be read, in the words the pane and `fn`
|
|
100
|
+
* show, or null for a failure worth reporting as one: the history is Gloom
|
|
101
|
+
* Pro, and a bond the store cannot tie to a company has none.
|
|
102
|
+
*/
|
|
103
|
+
export function storedHistoryRefusal(error: unknown): string | null {
|
|
104
|
+
if (!(error instanceof ApiRequestError)) return null;
|
|
105
|
+
if (error.status === 401 || error.status === 403) return PRO_HISTORY_TEXT;
|
|
106
|
+
if (error.status === 404) return "No kept price history for this bond.";
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A bond's kept history for the pane, or why there is none to read; any other failure is thrown. */
|
|
111
|
+
export async function loadStoredBond(
|
|
112
|
+
cusip: string,
|
|
113
|
+
client: Pick<StoredBondClient, "getCloudStoredBond">,
|
|
114
|
+
options: { signal?: AbortSignal; now?: number } = {},
|
|
115
|
+
): Promise<{ history: StoredBondPayload | null; refusal: string | null }> {
|
|
116
|
+
try {
|
|
117
|
+
const history = await client.getCloudStoredBond(cusip, { ...storedHistoryWindow(options.now), limit: STORED_PRINTS_LIMIT }, { signal: options.signal });
|
|
118
|
+
return { history, refusal: null };
|
|
119
|
+
} catch (error) {
|
|
120
|
+
const refusal = storedHistoryRefusal(error);
|
|
121
|
+
if (!refusal) throw error;
|
|
122
|
+
return { history: null, refusal };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* What a TRACE lookup reads of the kept history: one bond's, by its CUSIP;
|
|
128
|
+
* for a ticker, its company's bonds are kept from now on (no history is
|
|
129
|
+
* shown for them until one is opened). Null for a market-wide tape or a
|
|
130
|
+
* name the store cannot read.
|
|
131
|
+
*/
|
|
132
|
+
export async function readStoredHistory(
|
|
133
|
+
query: BondQuery | null,
|
|
134
|
+
client: StoredBondClient,
|
|
135
|
+
options: { signal?: AbortSignal; days?: number; now?: number } = {},
|
|
136
|
+
): Promise<StoredBondPayload | null> {
|
|
137
|
+
if (!query) return null;
|
|
138
|
+
if (query.kind === "cusip") {
|
|
139
|
+
return client.getCloudStoredBond(query.cusip, {
|
|
140
|
+
...storedHistoryWindow(options.now, options.days),
|
|
141
|
+
limit: STORED_PRINTS_LIMIT,
|
|
142
|
+
}, { signal: options.signal });
|
|
143
|
+
}
|
|
144
|
+
// Asked so its bonds are kept, never waited on for long: the tape is the answer here.
|
|
145
|
+
if (query.ticker) {
|
|
146
|
+
const ticker = query.ticker;
|
|
147
|
+
await Promise.resolve()
|
|
148
|
+
.then(() => client.getCloudStoredIssuerBonds(ticker, { signal: signalWithTimeout(options.signal, ISSUER_KEEP_TIMEOUT_MS) }))
|
|
149
|
+
.catch(() => {
|
|
150
|
+
// Intentional ignore: keeping a company's bonds never changes the tape this report answers with.
|
|
151
|
+
return null;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo } from "react";
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
DataTableStackView,
|
|
4
4
|
loadingText,
|
|
5
5
|
Notice,
|
|
6
6
|
QueryBar,
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
type DataTableRootKeyContext,
|
|
14
14
|
} from "../../../components";
|
|
15
15
|
import { usePaneRefreshKey } from "../../../components/data-table/table-pane";
|
|
16
|
+
import { apiClient } from "../../../api-client";
|
|
17
|
+
import { usePlanAccess } from "../../../api-client/plan-access";
|
|
16
18
|
import { useAsyncResource } from "../../../react/async-resource";
|
|
17
19
|
import { useAutoRefresh } from "../../../react/auto-refresh";
|
|
18
20
|
import { usePaneInstance } from "../../../state/app/context";
|
|
@@ -31,6 +33,8 @@ import {
|
|
|
31
33
|
quotedCompanyName,
|
|
32
34
|
type CorporateBond,
|
|
33
35
|
} from "./client";
|
|
36
|
+
import { BondHistoryDetail } from "./detail";
|
|
37
|
+
import { loadStoredBond, PRO_HISTORY_TEXT } from "./history";
|
|
34
38
|
import {
|
|
35
39
|
DEFAULT_BOND_SORT,
|
|
36
40
|
TRACE_BONDS_PANE_ID,
|
|
@@ -55,6 +59,12 @@ function dash(value: string | null): string {
|
|
|
55
59
|
return value ?? "—";
|
|
56
60
|
}
|
|
57
61
|
|
|
62
|
+
/** What a bond's detail is called: its issuer, coupon and maturity, as a bond is named. */
|
|
63
|
+
function bondTitle(bond: CorporateBond): string {
|
|
64
|
+
return [bond.issuerName, bond.couponRate == null ? null : formatBondDecimal(bond.couponRate, 3), bond.maturityDate]
|
|
65
|
+
.filter(Boolean).join(" ");
|
|
66
|
+
}
|
|
67
|
+
|
|
58
68
|
export function TraceBondsPane({ focused, width, height }: PaneProps) {
|
|
59
69
|
const presetIssuer = usePaneInstance()?.params?.issuer ?? "";
|
|
60
70
|
const [query, setQuery] = usePluginPaneState("issuer", presetIssuer);
|
|
@@ -73,7 +83,6 @@ export function TraceBondsPane({ focused, width, height }: PaneProps) {
|
|
|
73
83
|
const { active: searchActive, focus: focusSearch, searchProps } = useQueryBarSearch();
|
|
74
84
|
|
|
75
85
|
useAutoRefresh(updatedAt, load);
|
|
76
|
-
usePaneRefreshKey(() => void reload(), { focused, enabled: !searchActive });
|
|
77
86
|
|
|
78
87
|
// One issuer's tape says its name once, in what was asked, not on every row.
|
|
79
88
|
const sharedIssuer = useMemo(() => sharesOneIssuer(bonds), [bonds]);
|
|
@@ -99,6 +108,38 @@ export function TraceBondsPane({ focused, width, height }: PaneProps) {
|
|
|
99
108
|
if (!selectedId || !rows.some((row) => row.id === selectedId)) setSelectedId(rows[0]!.id);
|
|
100
109
|
}, [answered, rows, selectedId, setSelectedId]);
|
|
101
110
|
|
|
111
|
+
// A bond opens on its kept prints: Enter on a row, and with Gloom Pro a CUSIP looked up opens on its own once.
|
|
112
|
+
const [detailOpen, setDetailOpen] = usePluginPaneState("detailOpen", false);
|
|
113
|
+
const selectedBond = rows.find((row) => row.id === selectedId) ?? null;
|
|
114
|
+
const access = usePlanAccess();
|
|
115
|
+
const pro = access.hasProAccess;
|
|
116
|
+
const openedFor = useRef<string | null>(null);
|
|
117
|
+
const asked = answered ? data.query : null;
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!pro || asked?.kind !== "cusip" || rows.length !== 1 || openedFor.current === asked.cusip) return;
|
|
120
|
+
openedFor.current = asked.cusip;
|
|
121
|
+
setDetailOpen(true);
|
|
122
|
+
}, [asked, pro, rows.length, setDetailOpen]);
|
|
123
|
+
// A ticker looked up keeps its company's bonds from now on, as `fn TRACE` does; nothing waits on it.
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (!pro || asked?.kind !== "issuer" || !asked.ticker) return;
|
|
126
|
+
const controller = new AbortController();
|
|
127
|
+
void apiClient.getCloudStoredIssuerBonds(asked.ticker, { signal: controller.signal }).catch(() => {
|
|
128
|
+
// Intentional ignore: keeping the company's bonds is a side effect; the tape shows without it.
|
|
129
|
+
});
|
|
130
|
+
return () => controller.abort();
|
|
131
|
+
}, [asked, pro]);
|
|
132
|
+
const detailCusip = detailOpen && selectedBond?.cusip ? selectedBond.cusip : null;
|
|
133
|
+
const historyRequest = useCallback(() => loadStoredBond(detailCusip!, apiClient), [detailCusip]);
|
|
134
|
+
const history = useAsyncResource(detailCusip && pro ? historyRequest : null);
|
|
135
|
+
// Without Pro, refused or failed: the detail says why in place of the prints.
|
|
136
|
+
const historyRefusal = !pro ? PRO_HISTORY_TEXT
|
|
137
|
+
: history.data?.refusal ?? (history.error && !history.data ? unavailableText("Kept price history") : null);
|
|
138
|
+
usePaneRefreshKey(() => {
|
|
139
|
+
void reload();
|
|
140
|
+
if (detailCusip && pro) history.load();
|
|
141
|
+
}, { focused, enabled: !searchActive });
|
|
142
|
+
|
|
102
143
|
const onHeaderClick = useCallback((columnId: string) => {
|
|
103
144
|
if (!isBondColumnId(columnId)) return;
|
|
104
145
|
setSort((current) => nextHeaderSort(shownBondSort(current, sharedIssuer), columnId, {
|
|
@@ -154,7 +195,7 @@ export function TraceBondsPane({ focused, width, height }: PaneProps) {
|
|
|
154
195
|
// A failure or a load for another query is the table's own message; the footer keeps the answered query's status.
|
|
155
196
|
usePaneStatusFooter({
|
|
156
197
|
registrationId: TRACE_BONDS_PANE_ID,
|
|
157
|
-
loading: loading && answered,
|
|
198
|
+
loading: (loading && answered) || (!!detailCusip && history.loading && !history.data),
|
|
158
199
|
error: answered ? error : null,
|
|
159
200
|
info: footerInfo,
|
|
160
201
|
});
|
|
@@ -165,8 +206,26 @@ export function TraceBondsPane({ focused, width, height }: PaneProps) {
|
|
|
165
206
|
});
|
|
166
207
|
|
|
167
208
|
return (
|
|
168
|
-
<
|
|
209
|
+
<DataTableStackView
|
|
169
210
|
focused={focused && !searchActive}
|
|
211
|
+
detailOpen={detailOpen && !!selectedBond}
|
|
212
|
+
onBack={() => setDetailOpen(false)}
|
|
213
|
+
detailTitle={selectedBond ? bondTitle(selectedBond) : undefined}
|
|
214
|
+
detailContent={selectedBond ? (
|
|
215
|
+
<BondHistoryDetail
|
|
216
|
+
bond={selectedBond}
|
|
217
|
+
history={history.data?.history ?? null}
|
|
218
|
+
loading={!!detailCusip && pro && history.loading && !history.data}
|
|
219
|
+
refusal={historyRefusal}
|
|
220
|
+
focused={focused && detailOpen}
|
|
221
|
+
width={width}
|
|
222
|
+
height={Math.max(0, height - 1)}
|
|
223
|
+
/>
|
|
224
|
+
) : null}
|
|
225
|
+
onActivate={(row) => {
|
|
226
|
+
setSelectedId(row.id);
|
|
227
|
+
setDetailOpen(true);
|
|
228
|
+
}}
|
|
170
229
|
rootWidth={width}
|
|
171
230
|
rootHeight={height}
|
|
172
231
|
rootBefore={(
|
|
@@ -6,6 +6,7 @@ import { debugLog } from "../utils/debug-log";
|
|
|
6
6
|
import { getPluginsDir } from "./loader";
|
|
7
7
|
import { encodeBuiltinDisabledPluginIds } from "./ownership";
|
|
8
8
|
import { pluginDirectoryNames } from "./plugin-names";
|
|
9
|
+
import { samePluginSeedFailure, type PluginSeedNotice } from "./seed-progress";
|
|
9
10
|
|
|
10
11
|
const log = debugLog.createLogger("plugin-seed");
|
|
11
12
|
|
|
@@ -37,6 +38,12 @@ export const EXTRACTED_PLUGINS = [
|
|
|
37
38
|
|
|
38
39
|
type ExtractedPlugin = (typeof EXTRACTED_PLUGINS)[number];
|
|
39
40
|
|
|
41
|
+
/** Where an install landed: its folder, and the sibling plugins it brought along. */
|
|
42
|
+
interface SeedInstall {
|
|
43
|
+
directory: string;
|
|
44
|
+
peers?: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
export interface SeedResult {
|
|
41
48
|
installed: string[];
|
|
42
49
|
failed: string[];
|
|
@@ -49,17 +56,18 @@ export interface SeedResult {
|
|
|
49
56
|
* was renamed sits in a directory under the old one. Missing that install would
|
|
50
57
|
* clone a second copy, and the loader refuses the duplicate id.
|
|
51
58
|
*/
|
|
52
|
-
function
|
|
53
|
-
return pluginDirectoryNames(directory).
|
|
59
|
+
function installedDirectory(directory: string, pluginsDir: string): string | null {
|
|
60
|
+
return pluginDirectoryNames(directory).find((name) => existsSync(join(pluginsDir, name))) ?? null;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
/**
|
|
57
64
|
* The plugins left to install, each neither recorded as seeded, installed
|
|
58
65
|
* already, nor switched off before the move, and the ids to record as seeded
|
|
59
66
|
* without installing them. After a launch's seed, `pending` is what it could
|
|
60
|
-
* not install.
|
|
67
|
+
* not install. Reads only the config and the plugins folder, so a launch can
|
|
68
|
+
* know before its first frame what it will install after.
|
|
61
69
|
*/
|
|
62
|
-
function classifyExtractedPlugins(config: AppConfig, pluginsDir: string): { pending: ExtractedPlugin[]; settled: string[] } {
|
|
70
|
+
export function classifyExtractedPlugins(config: AppConfig, pluginsDir: string = getPluginsDir()): { pending: ExtractedPlugin[]; settled: string[] } {
|
|
63
71
|
const alreadySeeded = new Set(config.seededPlugins ?? []);
|
|
64
72
|
// A previous owner that is now a group of built-ins counts as off only while
|
|
65
73
|
// all of them are, which is when its id is saved.
|
|
@@ -74,7 +82,7 @@ function classifyExtractedPlugins(config: AppConfig, pluginsDir: string): { pend
|
|
|
74
82
|
// Present already (installed by hand, or seeded before this record
|
|
75
83
|
// existed), or turned off before the move, which restoring it would
|
|
76
84
|
// override: recorded so we stop looking.
|
|
77
|
-
if (
|
|
85
|
+
if (installedDirectory(entry.directory, pluginsDir)
|
|
78
86
|
|| disabled.has(entry.id) || ("previousOwnerIds" in entry && entry.previousOwnerIds.some((id) => disabled.has(id)))) {
|
|
79
87
|
settled.push(entry.id);
|
|
80
88
|
continue;
|
|
@@ -85,30 +93,57 @@ function classifyExtractedPlugins(config: AppConfig, pluginsDir: string): { pend
|
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
/**
|
|
88
|
-
* Installs any extracted plugin the user has not seen yet
|
|
96
|
+
* Installs any extracted plugin the user has not seen yet, one at a time, and
|
|
97
|
+
* reports each as it settles (`onSettled`, with where it landed when it did).
|
|
98
|
+
* `plan` is what a launch worked out before its first frame, so each plugin it
|
|
99
|
+
* said it would install is reported, even one another Gloom installed since.
|
|
89
100
|
*
|
|
90
101
|
* Best effort by design: a failure is logged and retried on the next launch
|
|
91
102
|
* rather than recorded, because the common cause is being offline at startup and
|
|
92
|
-
* marking it seeded would silently drop the plugin forever.
|
|
103
|
+
* marking it seeded would silently drop the plugin forever. A plugin that is
|
|
104
|
+
* there by the time its turn comes (a sibling's install brought it along, or
|
|
105
|
+
* another Gloom running beside this one installed it) counts as installed.
|
|
93
106
|
*/
|
|
94
107
|
export async function seedExtractedPlugins(
|
|
95
108
|
config: AppConfig,
|
|
96
|
-
installPlugin: (ref: string) => Promise<
|
|
109
|
+
installPlugin: (ref: string) => Promise<SeedInstall | void>,
|
|
97
110
|
pluginsDir: string = getPluginsDir(),
|
|
111
|
+
onSettled?: (id: string, installed: SeedInstall | null) => void,
|
|
112
|
+
plan: { pending: readonly ExtractedPlugin[]; settled: readonly string[] } = classifyExtractedPlugins(config, pluginsDir),
|
|
98
113
|
): Promise<SeedResult> {
|
|
99
|
-
const { pending, settled } =
|
|
114
|
+
const { pending, settled } = plan;
|
|
100
115
|
const result: SeedResult = { installed: [], failed: [], seeded: [...config.seededPlugins ?? [], ...settled] };
|
|
116
|
+
// A report that fails never changes what happened to the install it reports.
|
|
117
|
+
const report = (id: string, installed: SeedInstall | null) => {
|
|
118
|
+
try {
|
|
119
|
+
onSettled?.(id, installed);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
log.error(`Could not report ${id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
101
124
|
|
|
102
125
|
for (const entry of pending) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
126
|
+
let installed: SeedInstall | null = null;
|
|
127
|
+
const present = installedDirectory(entry.directory, pluginsDir);
|
|
128
|
+
if (present) {
|
|
129
|
+
installed = { directory: present };
|
|
130
|
+
} else {
|
|
131
|
+
try {
|
|
132
|
+
log.info(`Restoring ${entry.id} from ${entry.repo}`);
|
|
133
|
+
installed = await installPlugin(entry.repo) ?? { directory: entry.directory };
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const raced = installedDirectory(entry.directory, pluginsDir);
|
|
136
|
+
if (raced) installed = { directory: raced };
|
|
137
|
+
else log.error(`Could not restore ${entry.id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (installed) {
|
|
106
141
|
result.installed.push(entry.id);
|
|
107
142
|
result.seeded.push(entry.id);
|
|
108
|
-
}
|
|
109
|
-
log.error(`Could not restore ${entry.id}: ${error}`);
|
|
143
|
+
} else {
|
|
110
144
|
result.failed.push(entry.id);
|
|
111
145
|
}
|
|
146
|
+
report(entry.id, installed);
|
|
112
147
|
}
|
|
113
148
|
|
|
114
149
|
return result;
|
|
@@ -134,16 +169,6 @@ export function pluginSeedFailure(failedIds: readonly string[], gitMissing: bool
|
|
|
134
169
|
return failedIds.length > 0 ? { plugins: [...new Set(failedIds)].sort(), gitMissing } : undefined;
|
|
135
170
|
}
|
|
136
171
|
|
|
137
|
-
/** Whether two recorded seed failures are the same: the same plugins, for the same reason. */
|
|
138
|
-
export function samePluginSeedFailure(a: PluginSeedFailure | undefined, b: PluginSeedFailure | undefined): boolean {
|
|
139
|
-
return a?.gitMissing === b?.gitMissing && (a?.plugins ?? []).join() === (b?.plugins ?? []).join();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export interface PluginSeedNotice {
|
|
143
|
-
body: string;
|
|
144
|
-
type: "error" | "info";
|
|
145
|
-
}
|
|
146
|
-
|
|
147
172
|
/**
|
|
148
173
|
* The one notice a launch shows when its seed left official plugins
|
|
149
174
|
* uninstalled. A missing git, the usual cause on Windows, is an error said at
|