gloomberb 0.20.4 → 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.
Files changed (217) hide show
  1. package/README.md +2 -0
  2. package/bin/gloom +9 -0
  3. package/bin/without-bun.cjs +98 -0
  4. package/package.json +3 -1
  5. package/src/api-client/data.ts +138 -35
  6. package/src/api-client/types/econ.ts +12 -0
  7. package/src/api-client/yield-curves.ts +1 -1
  8. package/src/app/global-shortcuts.ts +4 -1
  9. package/src/app/keybindings/actions.ts +6 -0
  10. package/src/app/keybindings/config.ts +2 -1
  11. package/src/app/keybindings/index.ts +1 -0
  12. package/src/app/keybindings/labels.ts +6 -1
  13. package/src/app/keybindings/resolve.ts +23 -4
  14. package/src/app/keybindings/terminal-keys.ts +35 -0
  15. package/src/app/pane-runtime/index.tsx +2 -2
  16. package/src/app/pane-runtime/ticker-open-runtime.ts +68 -40
  17. package/src/architecture/ui-literals-allowlist.json +1 -1
  18. package/src/capabilities/chart-series.ts +27 -1
  19. package/src/cli/commands/keybindings.ts +5 -5
  20. package/src/cli/commands/market.ts +78 -21
  21. package/src/cli/commands/news-search.ts +59 -7
  22. package/src/cli/commands/overview.ts +16 -1
  23. package/src/cli/commands/remote.ts +16 -17
  24. package/src/cli/commands/system.ts +1 -1
  25. package/src/cli/fx-forward.ts +25 -7
  26. package/src/cli/glossary.ts +19 -5
  27. package/src/cli/history-rows.ts +5 -3
  28. package/src/cli/known-gaps.ts +27 -1
  29. package/src/cli/listing-arg.ts +11 -1
  30. package/src/cli/name-entries.ts +5 -1
  31. package/src/cli/not-a-ticker.ts +4 -0
  32. package/src/cli/pane-functions/function-help.ts +2 -2
  33. package/src/components/command-bar/pane-settings.ts +2 -2
  34. package/src/components/command-bar/routes/root/results.ts +6 -2
  35. package/src/components/input-search-bar.tsx +9 -2
  36. package/src/components/layout/pane/header.tsx +2 -0
  37. package/src/components/layout/shell/pane/capture.ts +4 -1
  38. package/src/components/layout/status-bar.tsx +6 -1
  39. package/src/components/onboarding/first-run-workspace.ts +44 -2
  40. package/src/components/onboarding/onboarding-frame.tsx +11 -2
  41. package/src/components/onboarding/onboarding-keyboard.ts +16 -0
  42. package/src/components/onboarding/onboarding-wizard.tsx +8 -8
  43. package/src/components/onboarding/portfolio-step/positions-panel.tsx +62 -1
  44. package/src/components/onboarding/use-onboarding-progress.ts +12 -4
  45. package/src/components/pane-settings-dialog/desktop.tsx +2 -2
  46. package/src/components/pane-settings-dialog/tui.tsx +2 -2
  47. package/src/components/pane-settings-dialog/value.ts +6 -0
  48. package/src/components/pane-settings-dialog.tsx +3 -3
  49. package/src/components/reader/detail-reader.tsx +4 -0
  50. package/src/components/ui/index.ts +1 -1
  51. package/src/components/ui/page-stack-view.tsx +3 -0
  52. package/src/components/ui/pane-link-chip.tsx +269 -54
  53. package/src/components/ui/query-bar.tsx +2 -1
  54. package/src/components/ui/tabs.tsx +97 -19
  55. package/src/core/state/app/layout-reducer.ts +7 -0
  56. package/src/core/state/app/layout.ts +44 -7
  57. package/src/core/state/app/state.ts +1 -1
  58. package/src/core/state/app/types.ts +22 -2
  59. package/src/docs/snapshot.json +27 -10
  60. package/src/market-data/depositary-pair.ts +5 -3
  61. package/src/market-data/market/dated-previous-close.ts +94 -15
  62. package/src/market-data/market/status.ts +17 -1
  63. package/src/plugins/builtin/analytics/risk-client.ts +10 -4
  64. package/src/plugins/builtin/analytics/risk-episodes.ts +5 -4
  65. package/src/plugins/builtin/analytics/risk-headless.ts +4 -2
  66. package/src/plugins/builtin/analytics/risk-sectors.ts +91 -0
  67. package/src/plugins/builtin/awards/index.tsx +1 -1
  68. package/src/plugins/builtin/buildout/index.tsx +1 -0
  69. package/src/plugins/builtin/catalysts/index.tsx +2 -2
  70. package/src/plugins/builtin/cds/headless.ts +4 -0
  71. package/src/plugins/builtin/chart-composer/headless.ts +2 -1
  72. package/src/plugins/builtin/chart-composer/index.tsx +1 -0
  73. package/src/plugins/builtin/chat/content/composer.tsx +5 -4
  74. package/src/plugins/builtin/chat/content/index.tsx +12 -2
  75. package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -3
  76. package/src/plugins/builtin/chat/content/open-targets.ts +3 -3
  77. package/src/plugins/builtin/chat/layout.ts +5 -2
  78. package/src/plugins/builtin/chat/message/pane-chip.tsx +61 -40
  79. package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
  80. package/src/plugins/builtin/chat/pane-links/previews.ts +51 -5
  81. package/src/plugins/builtin/chat/pane-links/share-card.ts +36 -0
  82. package/src/plugins/builtin/cloud/askg/tool-display.ts +1 -0
  83. package/src/plugins/builtin/cloud/terminal-relay/redact.ts +5 -3
  84. package/src/plugins/builtin/commodity-balances/index.tsx +1 -0
  85. package/src/plugins/builtin/company-attention/index.tsx +1 -1
  86. package/src/plugins/builtin/company-kpis/headless.ts +3 -1
  87. package/src/plugins/builtin/company-kpis/index.tsx +2 -2
  88. package/src/plugins/builtin/cot/index.tsx +1 -1
  89. package/src/plugins/builtin/cpi/index.tsx +1 -1
  90. package/src/plugins/builtin/crypto-board/index.tsx +1 -0
  91. package/src/plugins/builtin/dividend-yield/index.tsx +1 -0
  92. package/src/plugins/builtin/doe/index.tsx +1 -1
  93. package/src/plugins/builtin/earnings-calls/headless.ts +5 -1
  94. package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
  95. package/src/plugins/builtin/econ/calendar-model.ts +74 -1
  96. package/src/plugins/builtin/econ/fred-catalog.ts +3 -1
  97. package/src/plugins/builtin/econ/index.tsx +1 -0
  98. package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
  99. package/src/plugins/builtin/econ-statistics/pane.tsx +6 -0
  100. package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
  101. package/src/plugins/builtin/executives/index.tsx +1 -0
  102. package/src/plugins/builtin/filing-events/index.tsx +1 -0
  103. package/src/plugins/builtin/fixed-income/index.tsx +1 -0
  104. package/src/plugins/builtin/futures-curve/headless.ts +3 -3
  105. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  106. package/src/plugins/builtin/futures-curve/model.ts +18 -0
  107. package/src/plugins/builtin/gpu/index.tsx +1 -1
  108. package/src/plugins/builtin/help/functions-table.tsx +1 -1
  109. package/src/plugins/builtin/help/index.tsx +11 -1
  110. package/src/plugins/builtin/help/keybindings-editor.tsx +1 -1
  111. package/src/plugins/builtin/holders/index.tsx +1 -0
  112. package/src/plugins/builtin/holders/report-header.ts +2 -2
  113. package/src/plugins/builtin/insider/index.tsx +1 -0
  114. package/src/plugins/builtin/iv-history/index.tsx +1 -1
  115. package/src/plugins/builtin/jobs/index.tsx +1 -0
  116. package/src/plugins/builtin/macro-day/headless.ts +27 -8
  117. package/src/plugins/builtin/macro-day/index.tsx +1 -1
  118. package/src/plugins/builtin/macro-day/model.ts +19 -3
  119. package/src/plugins/builtin/macro-day/pane.tsx +14 -9
  120. package/src/plugins/builtin/macro-day/releases.ts +25 -7
  121. package/src/plugins/builtin/market-valuation/index.tsx +1 -0
  122. package/src/plugins/builtin/market-valuation/pane.tsx +8 -0
  123. package/src/plugins/builtin/members/index.tsx +1 -1
  124. package/src/plugins/builtin/mna/index.tsx +1 -0
  125. package/src/plugins/builtin/news/index.tsx +1 -0
  126. package/src/plugins/builtin/news/wire/index.tsx +5 -1
  127. package/src/plugins/builtin/news/wire/news/detail-view.tsx +4 -0
  128. package/src/plugins/builtin/news/wire/news/list-search.ts +5 -2
  129. package/src/plugins/builtin/options/index.tsx +1 -0
  130. package/src/plugins/builtin/options-positioning/index.tsx +1 -0
  131. package/src/plugins/builtin/pe-band/index.tsx +1 -1
  132. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +25 -0
  133. package/src/plugins/builtin/portfolio-list/headless.ts +15 -6
  134. package/src/plugins/builtin/power/index.tsx +1 -1
  135. package/src/plugins/builtin/realized-vol/index.tsx +1 -1
  136. package/src/plugins/builtin/research/headless.ts +10 -4
  137. package/src/plugins/builtin/research/index.tsx +4 -0
  138. package/src/plugins/builtin/research-search/index.tsx +1 -0
  139. package/src/plugins/builtin/research-search/pane.tsx +8 -0
  140. package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
  141. package/src/plugins/builtin/reverse-dcf/index.tsx +1 -1
  142. package/src/plugins/builtin/risk-factors/index.tsx +1 -0
  143. package/src/plugins/builtin/scanner/headless.ts +52 -13
  144. package/src/plugins/builtin/seasonality/index.tsx +1 -1
  145. package/src/plugins/builtin/sec/index.tsx +1 -0
  146. package/src/plugins/builtin/series-inventory.ts +1 -1
  147. package/src/plugins/builtin/shared/scanner-capture.ts +11 -3
  148. package/src/plugins/builtin/shared/series-list-detail.tsx +5 -0
  149. package/src/plugins/builtin/short-interest/index.tsx +1 -0
  150. package/src/plugins/builtin/social-mentions/index.tsx +1 -1
  151. package/src/plugins/builtin/supply-chain/index.tsx +1 -0
  152. package/src/plugins/builtin/thirteenf/data.ts +43 -10
  153. package/src/plugins/builtin/thirteenf/headless.ts +55 -11
  154. package/src/plugins/builtin/thirteenf/model.ts +25 -9
  155. package/src/plugins/builtin/thirteenf/report-notes.ts +27 -6
  156. package/src/plugins/builtin/thirteenf/types.ts +2 -0
  157. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +1 -1
  158. package/src/plugins/builtin/ticker-detail/financials/model.ts +12 -0
  159. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +3 -3
  160. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +5 -5
  161. package/src/plugins/builtin/ticker-detail/headless.ts +18 -13
  162. package/src/plugins/builtin/ticker-detail/index.tsx +4 -0
  163. package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
  164. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +6 -4
  165. package/src/plugins/builtin/time-sales/client.ts +9 -11
  166. package/src/plugins/builtin/time-sales/index.tsx +1 -1
  167. package/src/plugins/builtin/treasury-auctions/after.ts +267 -0
  168. package/src/plugins/builtin/treasury-auctions/cache.ts +18 -3
  169. package/src/plugins/builtin/treasury-auctions/client.ts +33 -2
  170. package/src/plugins/builtin/treasury-auctions/headless.ts +109 -19
  171. package/src/plugins/builtin/treasury-auctions/index.tsx +14 -4
  172. package/src/plugins/builtin/treasury-auctions/model.ts +256 -28
  173. package/src/plugins/builtin/treasury-auctions/pane.tsx +139 -28
  174. package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +5 -2
  175. package/src/plugins/builtin/treasury-auctions/types.ts +7 -1
  176. package/src/plugins/builtin/vol-surface/index.tsx +1 -1
  177. package/src/plugins/builtin/world-venue-map/index.ts +1 -0
  178. package/src/plugins/builtin/yield-curve/curves.ts +10 -4
  179. package/src/plugins/builtin/yield-curve/headless.ts +6 -2
  180. package/src/plugins/builtin/yield-curve/index.tsx +3 -3
  181. package/src/plugins/builtin/yield-curve/series.ts +10 -0
  182. package/src/plugins/builtin/yield-curve/world.ts +3 -1
  183. package/src/portfolio/column-values.ts +2 -1
  184. package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
  185. package/src/public/remote.ts +7 -1
  186. package/src/remote/client.ts +191 -11
  187. package/src/remote/controller-utils.ts +13 -1
  188. package/src/remote/controller.ts +88 -26
  189. package/src/remote/endpoint.ts +24 -0
  190. package/src/remote/form.ts +59 -4
  191. package/src/remote/resources.ts +44 -18
  192. package/src/remote/schema.ts +21 -9
  193. package/src/remote/secrets.ts +12 -0
  194. package/src/remote/semantic-tree.tsx +14 -2
  195. package/src/remote/server.ts +2 -1
  196. package/src/remote/surface.tsx +192 -0
  197. package/src/remote/types.ts +5 -0
  198. package/src/renderers/opentui/host.tsx +6 -0
  199. package/src/series/standalone.ts +2 -2
  200. package/src/shares/api.ts +21 -4
  201. package/src/shares/item.ts +73 -0
  202. package/src/shares/pane-item.ts +205 -0
  203. package/src/shares/pane.ts +4 -0
  204. package/src/shares/payload.ts +9 -5
  205. package/src/sources/gloomberb-cloud/news.ts +2 -0
  206. package/src/tickers/renamed-listings.ts +105 -0
  207. package/src/tickers/search/index.ts +103 -16
  208. package/src/time-series/resolve.ts +2 -2
  209. package/src/types/financials.ts +1 -0
  210. package/src/types/plugin-pane-settings.ts +2 -0
  211. package/src/types/plugin-panes.ts +22 -0
  212. package/src/utils/central-banks.ts +86 -1
  213. package/src/utils/datetime-format.ts +12 -3
  214. package/src/utils/depositary-receipt.ts +28 -3
  215. package/src/utils/fundamentals.ts +14 -0
  216. package/src/utils/max-drawdown.ts +97 -16
  217. package/src/utils/untrusted-text.ts +29 -0
package/README.md CHANGED
@@ -47,6 +47,8 @@ Or with [Bun](https://bun.sh), on any of them:
47
47
  bun install -g @gloom-sh/terminal
48
48
  ```
49
49
 
50
+ `npm install -g @gloom-sh/terminal` works too, but the command runs on Bun, so install [Bun](https://bun.sh) first.
51
+
50
52
  Then run `gloom` (`gloomberb`, its old name, still works). On Apple Silicon the script also installs the desktop app, Gloom.app. Homebrew, the Windows desktop installer and manual downloads are in the [installation guide](docs/installation.md).
51
53
 
52
54
  Charts draw as images in Kitty-compatible terminals such as Ghostty, Kitty and WezTerm, and as text elsewhere.
package/bin/gloom CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  // The package installs this as both `gloom` and `gloomberb`.
4
4
  //
5
+ // npm on a machine without Bun points this file at Node instead
6
+ // (without-bun.cjs, its preinstall): Node hands over to Bun once there is
7
+ // one, or says in one line how to get it.
8
+ if (!process.versions.bun) {
9
+ const { runWithoutBun } = await import("./without-bun.cjs");
10
+ const { fileURLToPath } = await import("node:url");
11
+ process.exit(await runWithoutBun(fileURLToPath(import.meta.url), process.argv.slice(2)));
12
+ }
13
+
5
14
  // Bun applies patchedDependencies only to the root project, so a global
6
15
  // `bun install -g` runs react-reconciler without
7
16
  // patches/react-reconciler@0.33.0.patch. Its dev build then records a
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ // Gloom runs on Bun, and `bin/gloom` starts with `#!/usr/bin/env bun`. npm and
4
+ // npx install it on machines without Bun too, where that line failed with
5
+ // "env: bun: No such file or directory" before any of Gloom ran.
6
+ //
7
+ // Run as npm's preinstall (before npm links the command, so Windows' shims
8
+ // follow it too), this points the command at Node when no Bun is found.
9
+ // Under Node, `bin/gloom` then hands over to Bun once one is installed, or
10
+ // says in one line how to get it (runWithoutBun). A machine with Bun, and
11
+ // every Bun install, keeps the Bun line untouched. Never fails an install.
12
+
13
+ const { existsSync, readFileSync, writeFileSync } = require("node:fs");
14
+ const { homedir } = require("node:os");
15
+ const { delimiter, join } = require("node:path");
16
+
17
+ const BUN_LINE = "#!/usr/bin/env bun";
18
+ const NODE_LINE = "#!/usr/bin/env node";
19
+
20
+ /**
21
+ * A Bun on PATH, or where Bun's installer puts it; null when there is none.
22
+ * On Windows only bun.exe counts, as Node cannot start a .cmd shim without a
23
+ * shell: an npm-installed Bun is found by the bun.exe beside its shims.
24
+ */
25
+ function findBun(env = process.env, platform = process.platform) {
26
+ const dirs = [
27
+ ...(env.PATH ?? env.Path ?? "").split(platform === "win32" ? ";" : delimiter),
28
+ join(env.BUN_INSTALL || join(homedir(), ".bun"), "bin"),
29
+ ].filter(Boolean);
30
+ for (const dir of dirs) {
31
+ const candidates = platform === "win32"
32
+ ? [join(dir, "bun.exe"), join(dir, "node_modules", "bun", "bin", "bun.exe")]
33
+ : [join(dir, "bun")];
34
+ const found = candidates.find((candidate) => existsSync(candidate));
35
+ if (found) return found;
36
+ }
37
+ return null;
38
+ }
39
+
40
+ /** The one line a machine without Bun gets, naming both ways out. */
41
+ function missingBunMessage(platform = process.platform) {
42
+ return platform === "win32"
43
+ ? "gloom runs on Bun, which is not installed. Install Bun (powershell -c \"irm bun.sh/install.ps1 | iex\") and run gloom again, or install Gloom with: irm https://gloom.sh/install.ps1 | iex"
44
+ : "gloom runs on Bun, which is not installed. Install Bun (curl -fsSL https://bun.sh/install | bash) and run gloom again, or install Gloom with: curl -fsSL https://gloom.sh/install | bash";
45
+ }
46
+
47
+ /**
48
+ * Points `launcher` at Node when npm installs it on a machine with no Bun.
49
+ * True when it changed it. A Bun install, and a source checkout (not under
50
+ * node_modules), keep the Bun line.
51
+ */
52
+ function useNodeWithoutBun(launcher, env = process.env, platform = process.platform) {
53
+ if ((env.npm_config_user_agent ?? "").startsWith("bun/")) return false;
54
+ if (!launcher.split(/[\\/]/).includes("node_modules")) return false;
55
+ if (findBun(env, platform)) return false;
56
+ const text = readFileSync(launcher, "utf8");
57
+ if (!text.startsWith(`${BUN_LINE}\n`)) return false;
58
+ writeFileSync(launcher, `${NODE_LINE}\n${text.slice(BUN_LINE.length + 1)}`);
59
+ return true;
60
+ }
61
+
62
+ /**
63
+ * `bin/gloom` under Node: runs `script` with the Bun found now, passing the
64
+ * arguments, stdio and exit status through, or prints missingBunMessage.
65
+ * Resolves to the exit code.
66
+ */
67
+ function runWithoutBun(script, args) {
68
+ const bun = findBun();
69
+ if (!bun) {
70
+ process.stderr.write(`${missingBunMessage()}\n`);
71
+ return Promise.resolve(1);
72
+ }
73
+ const { spawn } = require("node:child_process");
74
+ const { constants } = require("node:os");
75
+ return new Promise((resolve) => {
76
+ const child = spawn(bun, [script, ...args], { stdio: "inherit" });
77
+ // The terminal sends Ctrl+C to Bun as well; Node waits for it to finish.
78
+ const ignore = () => {};
79
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) process.on(signal, ignore);
80
+ child.on("error", (error) => {
81
+ process.stderr.write(`gloom: could not start Bun at ${bun}: ${error.message}\n`);
82
+ resolve(1);
83
+ });
84
+ child.on("exit", (code, signal) => {
85
+ resolve(code ?? 128 + (signal ? constants.signals[signal] ?? 0 : 0));
86
+ });
87
+ });
88
+ }
89
+
90
+ module.exports = { findBun, missingBunMessage, runWithoutBun, useNodeWithoutBun };
91
+
92
+ if (require.main === module && !process.versions.bun) {
93
+ try {
94
+ useNodeWithoutBun(join(__dirname, "gloom"));
95
+ } catch {
96
+ // Intentional ignore: a launcher that cannot be rewritten keeps the Bun line, as before.
97
+ }
98
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gloomberb",
3
- "version": "0.20.4",
3
+ "version": "0.20.5",
4
4
  "packageManager": "bun@1.3.14",
5
5
  "description": "Market research and portfolio tracker for the terminal",
6
6
  "module": "src/public/index.ts",
@@ -51,6 +51,7 @@
51
51
  "patches"
52
52
  ],
53
53
  "scripts": {
54
+ "preinstall": "node bin/without-bun.cjs || exit 0",
54
55
  "dev": "bun run --watch src/cli/entry.ts",
55
56
  "start": "bun src/cli/entry.ts",
56
57
  "build": "bun run scripts/build.ts",
@@ -94,6 +95,7 @@
94
95
  "check:pane-layout": "bun run scripts/pane-chrome/layout-sweep.ts",
95
96
  "check:ui-tokens": "bun run scripts/pane-chrome/ui-tokens.ts",
96
97
  "ui:benchmark": "bun run scripts/pane-chrome/ui-benchmark.ts",
98
+ "askg:tool-sweep": "bun run scripts/askg-tool-sweep.ts",
97
99
  "ui:badge-ink": "bun run scripts/pane-chrome/badge-ink.ts",
98
100
  "audit:ui": "bun run scripts/pane-chrome/ui-audit.ts",
99
101
  "check:call-player": "bun run scripts/pane-chrome/call-player.ts",
@@ -55,7 +55,7 @@ import type { GpuBoardPayload, GpuEventsPayload, GpuHistoryPayload, GpuHistoryQu
55
55
  import type { CpiBoardPayload } from "./cpi";
56
56
  import type { TapeRange, TapeSnapshot } from "./tape";
57
57
  import { LIVE_SCAN_PATH, type LiveScanPayload, type LiveScanWireDefinition } from "./live-scan";
58
- import { signalWithTimeout } from "../utils/async-deadline";
58
+ import { abortable, signalWithTimeout } from "../utils/async-deadline";
59
59
  import { ApiRequestError, isRetryableApiError, markAskedTwice } from "./errors";
60
60
  import type { ExchangeRateSnapshot } from "../types/exchange-rate";
61
61
  import type { RatePathPayload } from "./rates";
@@ -235,6 +235,33 @@ export interface BatchableRead {
235
235
  batch?: boolean;
236
236
  }
237
237
 
238
+ const DAY_MS = 86_400_000;
239
+
240
+ /** A YYYY-MM-DD date `days` away as a UTC time, or null for any other form, which bounds nothing. */
241
+ function dayTime(date: string | undefined, days: number): number | null {
242
+ if (!date || !/^\d{4}-\d{2}-\d{2}$/.test(date)) return null;
243
+ const time = Date.parse(`${date}T00:00:00Z`);
244
+ return Number.isFinite(time) ? time + days * DAY_MS : null;
245
+ }
246
+
247
+ /**
248
+ * Whether every bar falls in the window asked, give or take the day a daily
249
+ * bar's UTC time may stand from its session's date. A server from before
250
+ * windowed batches answers its latest bars instead, which this tells apart.
251
+ */
252
+ function withinWindow(points: readonly CloudPricePointPayload[] | null | undefined, startDate?: string, endDate?: string): boolean {
253
+ if (!Array.isArray(points)) return true;
254
+ const from = dayTime(startDate, -2);
255
+ const before = dayTime(endDate, 2);
256
+ return points.every((point) => {
257
+ const time = Date.parse(point.date);
258
+ return !Number.isFinite(time) || ((from == null || time >= from) && (before == null || time < before));
259
+ });
260
+ }
261
+
262
+ /** What a service without windowed batches is taken to have answered: the route missing, so the reads go out alone until it is asked again. */
263
+ const WINDOWLESS_BATCH = "The history batch route does not read a window of dates";
264
+
238
265
  export class CloudDataApi {
239
266
  constructor(
240
267
  private readonly request: CloudApiRequest,
@@ -250,36 +277,97 @@ export class CloudDataApi {
250
277
  * board's seventy-two rows are five requests, and the first rows land as
251
278
  * soon as sixteen reads have.
252
279
  */
253
- private readonly histories = createReadCoalescer<
254
- { symbol: string; exchange: string; params: Pick<CloudHistoryParams, "interval" | "outputsize" | "rangeKey"> },
255
- CloudMarketResponse<CloudPricePointPayload[]>
256
- >({
257
- max: 16,
258
- // Reads asked alone after a refused batch stay within what the panes kept in flight before: SOVR four, the board twelve with its terms.
259
- fallbackConcurrency: 4,
260
- group: ({ params }) => `${params.interval ?? ""}|${params.outputsize ?? ""}|${params.rangeKey ?? ""}`,
261
- single: ({ symbol, exchange, params }) => this.request(cloudHistoryPath(symbol, exchange, params)),
262
- batch: async (keys) => {
263
- const { interval, outputsize, rangeKey } = keys[0]!.params;
264
- // The server answers each target in the order asked, so a listing asked twice is asked once.
265
- const targetKey = ({ symbol, exchange }: { symbol: string; exchange: string }) => `${symbol}\u001f${exchange}`;
266
- const targets = [...new Map(keys.map((key) => [targetKey(key), { symbol: key.symbol, exchange: key.exchange }])).values()];
267
- const response = await this.request<CloudMarketResponse<{ items: Array<CloudMarketResponse<CloudPricePointPayload[]>> }>>("/market/history/batch", {
268
- method: "POST",
269
- body: JSON.stringify({
270
- targets,
271
- interval: interval ?? "1day",
272
- ...(outputsize != null ? { outputsize: String(outputsize) } : {}),
273
- ...(rangeKey ? { rangeKey } : {}),
274
- }),
275
- });
276
- const items = response.data?.items;
277
- // An answer that does not line up with the targets asked is not matched by place: each read is asked on its own.
278
- if (!Array.isArray(items) || items.length !== targets.length) return keys.map(() => undefined);
279
- const byTarget = new Map(targets.map((target, index) => [targetKey(target), items[index]]));
280
- return keys.map((key) => byTarget.get(targetKey(key)));
281
- },
282
- });
280
+ private readonly histories = this.historyCoalescer(false);
281
+
282
+ /**
283
+ * The same over one window of dates (a portfolio's holdings over the risk
284
+ * model's months or the stress episodes' years). A service from before
285
+ * windowed batches answers its latest bars instead, or refuses the window:
286
+ * that reads as the route missing, so the reads are asked on their own,
287
+ * four at a time, until it is asked again. Until a windowed batch has been
288
+ * answered, one read is asked as a batch of its own first (`windowProbe`),
289
+ * so finding that out costs one listing's bars, not every batch's.
290
+ */
291
+ private readonly datedHistories = this.historyCoalescer(true);
292
+ /** The first windowed batch, of one read, that the others wait on; null until asked, and again after it found no windows. */
293
+ private windowProbe: Promise<CloudMarketResponse<CloudPricePointPayload[]> | undefined> | null = null;
294
+ /** Whether a windowed batch has come back over its window: the probe is not asked again. */
295
+ private windowsAnswered = false;
296
+
297
+ private historyCoalescer(dated: boolean) {
298
+ return createReadCoalescer<
299
+ { symbol: string; exchange: string; params: Pick<CloudHistoryParams, "interval" | "outputsize" | "rangeKey" | "startDate" | "endDate"> },
300
+ CloudMarketResponse<CloudPricePointPayload[]>
301
+ >({
302
+ max: 16,
303
+ // Reads asked alone after a refused batch stay within what the panes kept in flight before: SOVR four, the board twelve with its terms.
304
+ fallbackConcurrency: 4,
305
+ group: ({ params }) => [params.interval, params.outputsize, params.rangeKey, params.startDate, params.endDate].map((value) => value ?? "").join("|"),
306
+ single: ({ symbol, exchange, params }) => this.request(cloudHistoryPath(symbol, exchange, params)),
307
+ batch: (keys) => (dated ? this.windowedBatch(keys) : this.historyBatch(keys, false)),
308
+ });
309
+ }
310
+
311
+ private async historyBatch(
312
+ keys: Array<{ symbol: string; exchange: string; params: Pick<CloudHistoryParams, "interval" | "outputsize" | "rangeKey" | "startDate" | "endDate"> }>,
313
+ dated: boolean,
314
+ ): Promise<Array<CloudMarketResponse<CloudPricePointPayload[]> | undefined>> {
315
+ const { interval, outputsize, rangeKey, startDate, endDate } = keys[0]!.params;
316
+ // The server answers each target in the order asked, so a listing asked twice is asked once.
317
+ const targetKey = ({ symbol, exchange }: { symbol: string; exchange: string }) => `${symbol}\u001f${exchange}`;
318
+ const targets = [...new Map(keys.map((key) => [targetKey(key), { symbol: key.symbol, exchange: key.exchange }])).values()];
319
+ const response = await this.request<CloudMarketResponse<{ items: Array<CloudMarketResponse<CloudPricePointPayload[]>> }>>("/market/history/batch", {
320
+ method: "POST",
321
+ body: JSON.stringify({
322
+ targets,
323
+ interval: interval ?? "1day",
324
+ ...(outputsize != null ? { outputsize: String(outputsize) } : {}),
325
+ ...(rangeKey ? { rangeKey } : {}),
326
+ ...(dated && startDate ? { startDate } : {}),
327
+ ...(dated && endDate ? { endDate } : {}),
328
+ }),
329
+ }).catch((error: unknown) => {
330
+ // A service that does not take a window in a batch may refuse it as asked rather than answer its latest bars.
331
+ if (dated && error instanceof ApiRequestError && (error.status === 400 || error.status === 422)) throw new ApiRequestError(WINDOWLESS_BATCH, 404);
332
+ throw error;
333
+ });
334
+ const items = response.data?.items;
335
+ // An answer that does not line up with the targets asked is not matched by place: each read is asked on its own.
336
+ if (!Array.isArray(items) || items.length !== targets.length) return keys.map(() => undefined);
337
+ if (dated && items.some((item) => !withinWindow(item.data, startDate, endDate))) throw new ApiRequestError(WINDOWLESS_BATCH, 404);
338
+ const byTarget = new Map(targets.map((target, index) => [targetKey(target), items[index]]));
339
+ return keys.map((key) => byTarget.get(targetKey(key)));
340
+ }
341
+
342
+ /**
343
+ * A batch over a window, once a windowed batch has been answered; before
344
+ * that, the first batch's first read goes out alone as the probe and every
345
+ * batch waits on it. A probe answered with bars outside its window, or
346
+ * refused, fails them all as the missing route; one answered with bars in it
347
+ * lets them go, and its own read is not asked again.
348
+ */
349
+ private async windowedBatch(
350
+ keys: Array<{ symbol: string; exchange: string; params: Pick<CloudHistoryParams, "interval" | "outputsize" | "rangeKey" | "startDate" | "endDate"> }>,
351
+ ): Promise<Array<CloudMarketResponse<CloudPricePointPayload[]> | undefined>> {
352
+ if (this.windowsAnswered) return this.historyBatch(keys, true);
353
+ const probing = !this.windowProbe;
354
+ const probe = this.windowProbe ??= this.historyBatch(keys.slice(0, 1), true).then(([item]) => {
355
+ // An empty answer shows no window either way: the batches that follow are checked as they come.
356
+ if (Array.isArray(item?.data) && item.data.length > 0) this.windowsAnswered = true;
357
+ return item;
358
+ });
359
+ let probed: CloudMarketResponse<CloudPricePointPayload[]> | undefined;
360
+ try {
361
+ probed = await probe;
362
+ } catch (error) {
363
+ // Asked again once the route is, after the missing route's wait.
364
+ if (this.windowProbe === probe) this.windowProbe = null;
365
+ throw error;
366
+ }
367
+ if (!probing) return this.historyBatch(keys, true);
368
+ const rest = keys.length > 1 ? await this.historyBatch(keys.slice(1), true) : [];
369
+ return [probed, ...rest];
370
+ }
283
371
 
284
372
  /**
285
373
  * Futures terms asked with others in the same moment (a futures board's rows) go out as
@@ -677,12 +765,27 @@ export class CloudDataApi {
677
765
  symbol: string,
678
766
  exchange: string,
679
767
  params: CloudHistoryParams = {},
680
- options: { signal?: AbortSignal } & BatchableRead = {},
768
+ options: {
769
+ signal?: AbortSignal;
770
+ /**
771
+ * With `batch`, the dates are the window every read asked with this one
772
+ * shares (a portfolio's holdings over the risk model's months), so they
773
+ * go out together over it.
774
+ */
775
+ sharedWindow?: boolean;
776
+ } & BatchableRead = {},
681
777
  ): Promise<CloudMarketResponse<CloudPricePointPayload[]>> {
682
- // Trailing bars asked with others, not a session, window or recovery of their own, may go out with the others asked in the same moment.
683
- const shared = options.batch && !options.signal && !params.startDate && !params.endDate && !params.historyRecovery && !params.session;
778
+ const dated = Boolean(params.startDate || params.endDate);
779
+ // Trailing bars asked with others, or bars over a window shared with them, not a session or recovery of their own,
780
+ // may go out with the others asked in the same moment. A read over a shared window keeps its signal: the batch it
781
+ // went out in is others' too and runs on, but the read stops waiting for it.
782
+ const shared = options.batch && !params.historyRecovery && !params.session && (dated ? options.sharedWindow : !options.signal);
684
783
  return this.readListing(() => shared
685
- ? this.histories.read({ symbol, exchange, params: { interval: params.interval, outputsize: params.outputsize, rangeKey: params.rangeKey } })
784
+ ? abortable((dated ? this.datedHistories : this.histories).read({
785
+ symbol,
786
+ exchange,
787
+ params: { interval: params.interval, outputsize: params.outputsize, rangeKey: params.rangeKey, startDate: params.startDate, endDate: params.endDate },
788
+ }), options.signal, "History read aborted")
686
789
  : this.request<CloudMarketResponse<CloudPricePointPayload[]>>(
687
790
  cloudHistoryPath(symbol, exchange, params),
688
791
  options.signal ? { signal: options.signal } : undefined,
@@ -47,6 +47,12 @@ export interface CloudShortRate {
47
47
  tenorDays: number;
48
48
  /** Days in the year the rate is quoted over. */
49
49
  dayCountBasis: 360 | 365;
50
+ /**
51
+ * "business-252": compounded over 252 business days a year (Brazil's CDI),
52
+ * grown as (1 + r)^(days / 365), business days taken as 252/365 of the
53
+ * calendar days. Absent: simple interest on `dayCountBasis`.
54
+ */
55
+ compounding?: "business-252" | null;
50
56
  publisher: string;
51
57
  sourceUrl: string;
52
58
  /** Percent a year; null when it could not be read. */
@@ -82,7 +88,13 @@ export interface CloudMacroReleaseDaysPayload {
82
88
  prior: string | null;
83
89
  /** Above the consensus (hot), below it (cool), at it (in-line); null without both. */
84
90
  surprise: "hot" | "cool" | "in-line" | null;
91
+ /** An FOMC day's move in the target range: "held", "cut 25bp", "raised 50bp". */
92
+ decision?: string;
85
93
  }>>>;
94
+ /** The first New York day the kept economic calendar covers: US days before it have no figures. */
95
+ figuresFrom?: string;
96
+ /** Why a US release day from `figuresFrom` on has no figures, by kind and day. */
97
+ figureGaps?: Partial<Record<"cpi" | "jobs" | "fomc", Record<string, string>>>;
86
98
  }
87
99
 
88
100
  export interface CloudFredObservationPayload {
@@ -1,5 +1,5 @@
1
1
  /** Government bond curves stored from their official publishers, in percent. */
2
- export type CloudCurveId = "us" | "us-real" | "us-breakeven" | "eu-aaa" | "de" | "gb" | "jp" | "ca";
2
+ export type CloudCurveId = "us" | "us-real" | "us-breakeven" | "eu-aaa" | "de" | "gb" | "jp" | "ca" | "mx" | "br";
3
3
 
4
4
  export interface CloudCurvePoint {
5
5
  tenor: string;
@@ -284,7 +284,10 @@ export function useAppGlobalShortcuts({
284
284
  if (ranAlready(action)) return;
285
285
  event.preventDefault();
286
286
  event.stopPropagation();
287
- pluginRegistry.showPane("help");
287
+ // The key that opened Help closes it again while it has focus.
288
+ const focused = state.focusedPaneId ? findPaneInstance(state.config.layout, state.focusedPaneId) : undefined;
289
+ if (focused?.paneId === "help") pluginRegistry.hidePane("help");
290
+ else pluginRegistry.showPane("help");
288
291
  return;
289
292
  }
290
293
 
@@ -44,6 +44,8 @@ export interface KeybindingActionDef {
44
44
  /** Help text. Kept in English here; the help pane translates it. */
45
45
  description: string;
46
46
  defaults: readonly string[];
47
+ /** Default chords the terminal adds after `defaults`, for keys only a terminal needs. */
48
+ terminalDefaults?: readonly string[];
47
49
  /** Only the desktop app has this action; the terminal hides the row. */
48
50
  desktopOnly?: boolean;
49
51
  /** Only the terminal has this action; the desktop app hides the row. */
@@ -109,6 +111,10 @@ export const KEYBINDING_ACTIONS: readonly KeybindingActionDef[] = [
109
111
  category: "Global Keys",
110
112
  description: "Switch saved layouts by number.",
111
113
  defaults: ["CmdOrCtrl+Digit"],
114
+ // A terminal without the kitty protocol never sends Control with a digit
115
+ // (Ctrl+1 arrives as 1, Ctrl+3 as Esc), but it sends Alt+1. A browser
116
+ // keeps Alt+1 for its own tabs, and a Mac types ¡ with it.
117
+ terminalDefaults: ["Alt+Digit"],
112
118
  },
113
119
  {
114
120
  id: "focus-next-pane",
@@ -19,7 +19,8 @@ export function updateKeybindingsConfig(config: AppConfig, keybindings: Keybindi
19
19
  function defaultChordsFor(actionId: string, defaults?: readonly KeyChord[]): readonly KeyChord[] {
20
20
  if (defaults) return defaults;
21
21
  const def = getKeybindingAction(actionId);
22
- return def ? def.defaults.map((text) => parseKeyChord(text)!).filter(Boolean) : [];
22
+ // Every host's defaults, as the table with no host has them.
23
+ return def ? [...def.defaults, ...def.terminalDefaults ?? []].map((text) => parseKeyChord(text)!).filter(Boolean) : [];
23
24
  }
24
25
 
25
26
  function sameChords(left: readonly KeyChord[], right: readonly KeyChord[]): boolean {
@@ -37,6 +37,7 @@ export {
37
37
  takenChordMessage,
38
38
  } from "./labels";
39
39
  export { KeybindingsProvider, getDefaultKeybindings, useKeybindings, useResolvedKeybindings } from "./react";
40
+ export { useTerminalReportsControlKeys } from "./terminal-keys";
40
41
  export {
41
42
  applyActionBinding,
42
43
  removeCommandBinding,
@@ -14,6 +14,7 @@ import {
14
14
  type PrimaryModifier,
15
15
  } from "./chord";
16
16
  import type { ResolvedKeybindingAction, ResolvedKeybindings } from "./resolve";
17
+ import { legacyTerminalSends } from "./terminal-keys";
17
18
 
18
19
  /** What `CmdOrCtrl` is on this host: Control in a terminal, Command on a Mac desktop. */
19
20
  export function primaryModifierFor(
@@ -103,10 +104,14 @@ export function advertisedChord(
103
104
  resolved: ResolvedKeybindings,
104
105
  actionId: string,
105
106
  mode: ShortcutDisplayMode,
107
+ { legacyTerminal = false }: {
108
+ /** The terminal answered without the kitty protocol: a chord it can send goes first (Alt+1 over Ctrl+1). */
109
+ legacyTerminal?: boolean;
110
+ } = {},
106
111
  ): KeyChord | null {
107
112
  const chords = chordsForHost(resolved.actionsById.get(actionId)?.chords ?? [], mode);
108
113
  if (chords.length === 0) return null;
109
- if (mode === "terminal") return chords[0]!;
114
+ if (mode === "terminal") return (legacyTerminal ? chords.find(legacyTerminalSends) : undefined) ?? chords[0]!;
110
115
  return chords.find((chord) => chord.primary || chord.cmd) ?? chords[0]!;
111
116
  }
112
117
 
@@ -113,6 +113,10 @@ function parseDefaults(texts: readonly string[]): KeyChord[] {
113
113
  }
114
114
 
115
115
  const DEFAULT_CHORDS = new Map(KEYBINDING_ACTIONS.map((action) => [action.id, parseDefaults(action.defaults)]));
116
+ const TERMINAL_DEFAULT_CHORDS = new Map(KEYBINDING_ACTIONS.map((action) => [
117
+ action.id,
118
+ [...DEFAULT_CHORDS.get(action.id)!, ...parseDefaults(action.terminalDefaults ?? [])],
119
+ ]));
116
120
 
117
121
  /**
118
122
  * Two chords fire on the same keypress somewhere: identical, or one says
@@ -179,11 +183,13 @@ export function resolveKeybindings(
179
183
  const hostActions = KEYBINDING_ACTIONS.filter((def) => (
180
184
  options.host === "desktop" ? !def.terminalOnly : options.host === "terminal" ? !def.desktopOnly : true
181
185
  ));
186
+ // With no host the table is every host's at once (the CLI), so it has the terminal's chords too.
187
+ const defaults = options.host === "desktop" ? DEFAULT_CHORDS : TERMINAL_DEFAULT_CHORDS;
182
188
  const actions: ResolvedKeybindingAction[] = hostActions.map((def) => resolveAction(
183
189
  def,
184
190
  undefined,
185
191
  def.id,
186
- DEFAULT_CHORDS.get(def.id)!,
192
+ defaults.get(def.id)!,
187
193
  overrides,
188
194
  issues,
189
195
  ));
@@ -229,12 +235,18 @@ export function resolveKeybindings(
229
235
 
230
236
  /**
231
237
  * The first action or command whose chord the event is, in table order. Actions
232
- * win over commands, so a stray command binding never shadows a core key.
238
+ * win over commands, so a stray command binding never shadows a core key. The
239
+ * one exception is a command on a single key of the 1-9 family (`Alt+1`):
240
+ * that key was bound by hand, the family by default, so the command keeps it.
233
241
  */
234
242
  export function matchKeybinding(resolved: ResolvedKeybindings, event: KeyChordEventLike): KeybindingMatch | null {
235
243
  for (const action of resolved.actions) {
236
244
  for (const chord of action.chords) {
237
245
  if (!matchesKeyChord(chord, event)) continue;
246
+ const command = chord.key === "digit"
247
+ ? resolved.commands.find((entry) => matchesKeyChord(entry.chord, event))
248
+ : undefined;
249
+ if (command) return { kind: "command", command };
238
250
  return {
239
251
  kind: "action",
240
252
  id: action.id,
@@ -255,11 +267,18 @@ export function matchKeybinding(resolved: ResolvedKeybindings, event: KeyChordEv
255
267
  * switcher's 1-9 included. Capture refuses such a chord, so a new binding never
256
268
  * leaves a core key (the command bar, close pane, quit) dead. Null when no
257
269
  * built-in action has it; a plugin shortcut or a bound command does not count.
270
+ * A command may take one digit of the 1-9 family (`Alt+1`): it wins that key
271
+ * (matchKeybinding), and the other eight still switch layouts.
258
272
  */
259
- export function coreActionOnChord(resolved: ResolvedKeybindings, chord: KeyChord, exceptId?: string): ResolvedKeybindingAction | null {
273
+ export function coreActionOnChord(
274
+ resolved: ResolvedKeybindings,
275
+ chord: KeyChord,
276
+ exceptId?: string,
277
+ { command = false }: { command?: boolean } = {},
278
+ ): ResolvedKeybindingAction | null {
260
279
  return resolved.actions.find((action) => action.def && action.id !== exceptId
261
280
  && action.chords.some((existing) => keyChordsOverlap(existing, chord)
262
- || (existing.key === "digit" && /^[1-9]$/.test(chord.key) && keyChordsOverlap({ ...existing, key: chord.key }, chord))))
281
+ || (!command && existing.key === "digit" && /^[1-9]$/.test(chord.key) && keyChordsOverlap({ ...existing, key: chord.key }, chord))))
263
282
  ?? null;
264
283
  }
265
284
 
@@ -0,0 +1,35 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import type { KeyChord } from "./chord";
3
+
4
+ /**
5
+ * Whether the terminal reports Control with any key (the kitty keyboard
6
+ * protocol), as the terminal host learns it from the terminal's answers at
7
+ * start: true when it does, false when the terminal answered without it, null
8
+ * before it answers and outside a terminal. Without the protocol Control
9
+ * never reaches a digit: Ctrl+1 arrives as 1, Ctrl+3 as Esc. Alt does, as Esc
10
+ * then the digit.
11
+ */
12
+ let reportsControlKeys: boolean | null = null;
13
+ const listeners = new Set<() => void>();
14
+
15
+ export function setTerminalReportsControlKeys(value: boolean | null): void {
16
+ if (value === reportsControlKeys) return;
17
+ reportsControlKeys = value;
18
+ for (const listener of listeners) listener();
19
+ }
20
+
21
+ function subscribe(listener: () => void): () => void {
22
+ listeners.add(listener);
23
+ return () => {
24
+ listeners.delete(listener);
25
+ };
26
+ }
27
+
28
+ export function useTerminalReportsControlKeys(): boolean | null {
29
+ return useSyncExternalStore(subscribe, () => reportsControlKeys, () => null);
30
+ }
31
+
32
+ /** Whether a terminal without the kitty protocol can send the chord: not Control with a digit. */
33
+ export function legacyTerminalSends(chord: KeyChord): boolean {
34
+ return !((chord.ctrl || chord.primary) && (chord.key === "digit" || /^[0-9]$/.test(chord.key)));
35
+ }
@@ -106,8 +106,8 @@ export function useAppPaneRuntime({
106
106
  ));
107
107
  }, [dispatch, stateRef]);
108
108
 
109
- const activatePane = useCallback((paneId: string) => {
110
- dispatch({ type: "FOCUS_PANE", paneId });
109
+ const activatePane = useCallback((paneId: string, options?: { trackTicker?: boolean }) => {
110
+ dispatch({ type: "FOCUS_PANE", paneId, ...options });
111
111
  }, [dispatch]);
112
112
 
113
113
  const {