gloomberb 0.4.1 → 0.5.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.
Files changed (212) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/app.tsx +168 -65
  4. package/src/cli/commands/ticker.ts +45 -15
  5. package/src/cli/helpers.ts +4 -2
  6. package/src/cli/registry.test.ts +42 -35
  7. package/src/cli.test.ts +4 -2
  8. package/src/components/chart/chart-control-hint.tsx +39 -0
  9. package/src/components/chart/chart-controller.test.ts +110 -0
  10. package/src/components/chart/chart-controller.ts +364 -2
  11. package/src/components/chart/chart-data.ts +177 -29
  12. package/src/components/chart/chart-indicator-selector.tsx +53 -0
  13. package/src/components/chart/chart-pane-settings.ts +20 -0
  14. package/src/components/chart/chart-renderer.ts +220 -30
  15. package/src/components/chart/chart-resolution.test.ts +67 -0
  16. package/src/components/chart/chart-resolution.ts +74 -4
  17. package/src/components/chart/chart-scroll.test.ts +69 -0
  18. package/src/components/chart/chart-scroll.ts +104 -0
  19. package/src/components/chart/chart-types.ts +12 -0
  20. package/src/components/chart/chart-viewport.test.ts +5 -1
  21. package/src/components/chart/chart-viewport.ts +1 -1
  22. package/src/components/chart/chart.test.ts +249 -10
  23. package/src/components/chart/comparison-chart-renderer.test.ts +71 -1
  24. package/src/components/chart/comparison-chart-renderer.ts +40 -3
  25. package/src/components/chart/comparison-stock-chart.tsx +218 -123
  26. package/src/components/chart/indicators/bands.test.ts +50 -0
  27. package/src/components/chart/indicators/bands.ts +29 -0
  28. package/src/components/chart/indicators/moving-averages.test.ts +54 -0
  29. package/src/components/chart/indicators/moving-averages.ts +42 -0
  30. package/src/components/chart/indicators/options.test.ts +32 -0
  31. package/src/components/chart/indicators/options.ts +107 -0
  32. package/src/components/chart/indicators/oscillators.test.ts +79 -0
  33. package/src/components/chart/indicators/oscillators.ts +92 -0
  34. package/src/components/chart/indicators/types.ts +36 -0
  35. package/src/components/chart/native/chart-rasterizer.ts +51 -0
  36. package/src/components/chart/native/kitty.test.ts +68 -0
  37. package/src/components/chart/stock-chart-renderer-switch.test.tsx +740 -9
  38. package/src/components/chart/stock-chart.test.ts +239 -0
  39. package/src/components/chart/stock-chart.tsx +2257 -372
  40. package/src/components/command-bar/command-bar.test.tsx +337 -5
  41. package/src/components/command-bar/command-bar.tsx +292 -120
  42. package/src/components/command-bar/helpers.ts +1 -1
  43. package/src/components/command-bar/root-shortcuts.ts +33 -4
  44. package/src/components/command-bar/view-model.test.ts +3 -3
  45. package/src/components/command-bar/view-model.ts +4 -4
  46. package/src/components/command-bar/workflow-ops.ts +10 -0
  47. package/src/components/layout/floating-pane.tsx +3 -2
  48. package/src/components/layout/header.tsx +2 -1
  49. package/src/components/layout/pane-sizing.ts +10 -0
  50. package/src/components/layout/pane.tsx +9 -2
  51. package/src/components/layout/shell.test.tsx +282 -28
  52. package/src/components/layout/shell.tsx +10 -7
  53. package/src/components/layout/status-bar.test.tsx +16 -7
  54. package/src/components/layout/status-bar.tsx +4 -1
  55. package/src/components/markdown-editor.tsx +1 -0
  56. package/src/components/pane-settings-dialog.tsx +13 -152
  57. package/src/components/pane-template-wizard.tsx +1 -0
  58. package/src/components/price-selector-dialog.tsx +12 -7
  59. package/src/components/ticker-badge-text.test.tsx +50 -0
  60. package/src/components/ticker-badge-text.tsx +17 -2
  61. package/src/components/ticker-badge.tsx +2 -2
  62. package/src/components/ticker-list-table.tsx +54 -1
  63. package/src/components/toggle-list.tsx +15 -2
  64. package/src/components/ui/data-table.tsx +60 -3
  65. package/src/components/ui/external-link.tsx +48 -11
  66. package/src/components/ui/fields.tsx +2 -1
  67. package/src/components/ui/index.ts +8 -1
  68. package/src/components/ui/multi-select-chips.tsx +69 -0
  69. package/src/components/ui/multi-select-dialog.tsx +267 -0
  70. package/src/components/ui/multi-select.ts +78 -0
  71. package/src/components/ui/ui.test.tsx +343 -1
  72. package/src/data/plugin-state-store.ts +30 -19
  73. package/src/data/resource-store.ts +133 -103
  74. package/src/data/session-store.ts +19 -12
  75. package/src/data/sqlite-cache.test.ts +37 -2
  76. package/src/data/sqlite-database.ts +8 -2
  77. package/src/data/sqlite-retry.test.ts +63 -0
  78. package/src/data/sqlite-retry.ts +66 -0
  79. package/src/data/ticker-store.ts +29 -18
  80. package/src/index.tsx +6 -1
  81. package/src/market-data/coordinator.test.ts +114 -5
  82. package/src/market-data/coordinator.ts +70 -1
  83. package/src/market-data/hooks.test.tsx +73 -2
  84. package/src/market-data/hooks.tsx +16 -4
  85. package/src/notifications/app-notifier.test.ts +177 -0
  86. package/src/notifications/app-notifier.ts +241 -0
  87. package/src/pane-settings.test.ts +2 -0
  88. package/src/plugins/builtin/ai/index.test.tsx +1 -1
  89. package/src/plugins/builtin/ai/screener-pane.test.tsx +2 -0
  90. package/src/plugins/builtin/ai/screener-pane.tsx +1 -0
  91. package/src/plugins/builtin/ai/ticker-context.ts +3 -2
  92. package/src/plugins/builtin/alerts/alert-engine.test.ts +90 -0
  93. package/src/plugins/builtin/alerts/alert-engine.ts +55 -0
  94. package/src/plugins/builtin/alerts/index.test.tsx +357 -0
  95. package/src/plugins/builtin/alerts/index.tsx +519 -0
  96. package/src/plugins/builtin/alerts/types.ts +14 -0
  97. package/src/plugins/builtin/analytics/index.test.tsx +300 -0
  98. package/src/plugins/builtin/analytics/index.tsx +775 -0
  99. package/src/plugins/builtin/analytics/metrics.test.ts +125 -0
  100. package/src/plugins/builtin/analytics/metrics.ts +155 -0
  101. package/src/plugins/builtin/ask-ai.test.tsx +2 -0
  102. package/src/plugins/builtin/chat-controller.test.ts +83 -18
  103. package/src/plugins/builtin/chat-controller.ts +26 -14
  104. package/src/plugins/builtin/chat.test.tsx +715 -4
  105. package/src/plugins/builtin/chat.tsx +424 -120
  106. package/src/plugins/builtin/comparison-chart.test.tsx +97 -57
  107. package/src/plugins/builtin/comparison-chart.tsx +1 -2
  108. package/src/plugins/builtin/correlation/compute.test.ts +147 -0
  109. package/src/plugins/builtin/correlation/compute.ts +115 -0
  110. package/src/plugins/builtin/correlation/index.tsx +385 -0
  111. package/src/plugins/builtin/correlation/plugin.test.ts +44 -0
  112. package/src/plugins/builtin/correlation/settings.test.ts +34 -0
  113. package/src/plugins/builtin/correlation/settings.ts +95 -0
  114. package/src/plugins/builtin/debug.tsx +36 -50
  115. package/src/plugins/builtin/earnings/earnings-cache.test.ts +181 -0
  116. package/src/plugins/builtin/earnings/earnings-cache.ts +136 -0
  117. package/src/plugins/builtin/earnings/earnings-data.test.ts +59 -0
  118. package/src/plugins/builtin/earnings/earnings-data.ts +50 -0
  119. package/src/plugins/builtin/earnings/index.tsx +337 -0
  120. package/src/plugins/builtin/econ/calendar-source.test.ts +219 -0
  121. package/src/plugins/builtin/econ/calendar-source.ts +121 -0
  122. package/src/plugins/builtin/econ/fred-client.test.ts +63 -0
  123. package/src/plugins/builtin/econ/fred-client.ts +79 -0
  124. package/src/plugins/builtin/econ/fred-series-map.ts +88 -0
  125. package/src/plugins/builtin/econ/index.tsx +999 -0
  126. package/src/plugins/builtin/econ/types.ts +13 -0
  127. package/src/plugins/builtin/fred-settings.ts +10 -0
  128. package/src/plugins/builtin/fx-matrix/index.tsx +178 -0
  129. package/src/plugins/builtin/fx-matrix/pairs.ts +30 -0
  130. package/src/plugins/builtin/help.test.tsx +1 -5
  131. package/src/plugins/builtin/help.tsx +1 -16
  132. package/src/plugins/builtin/insider/index.tsx +417 -0
  133. package/src/plugins/builtin/insider/insider-data.test.ts +55 -0
  134. package/src/plugins/builtin/insider/insider-data.ts +49 -0
  135. package/src/plugins/builtin/layout-manager.tsx +24 -16
  136. package/src/plugins/builtin/market-movers/index.tsx +573 -0
  137. package/src/plugins/builtin/market-movers/screener.test.ts +143 -0
  138. package/src/plugins/builtin/market-movers/screener.ts +105 -0
  139. package/src/plugins/builtin/options.tsx +4 -3
  140. package/src/plugins/builtin/portfolio-list/cli/commands.ts +11 -6
  141. package/src/plugins/builtin/portfolio-list/command-bar.ts +6 -3
  142. package/src/plugins/builtin/portfolio-list/header.tsx +3 -2
  143. package/src/plugins/builtin/portfolio-list/metrics.ts +22 -11
  144. package/src/plugins/builtin/portfolio-list/pane.tsx +3 -9
  145. package/src/plugins/builtin/portfolio-list/settings.ts +9 -0
  146. package/src/plugins/builtin/portfolio-list/table.tsx +3 -0
  147. package/src/plugins/builtin/portfolio-list.test.tsx +3 -1
  148. package/src/plugins/builtin/portfolio-metrics.test.ts +13 -1
  149. package/src/plugins/builtin/sec.tsx +114 -7
  150. package/src/plugins/builtin/sectors/index.tsx +359 -0
  151. package/src/plugins/builtin/sectors/sector-data.ts +18 -0
  152. package/src/plugins/builtin/ticker-detail/chart-tab.tsx +75 -13
  153. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +316 -80
  154. package/src/plugins/builtin/ticker-detail/quote-monitor.tsx +4 -6
  155. package/src/plugins/builtin/ticker-detail-chart-tab-switch.test.tsx +17 -12
  156. package/src/plugins/builtin/ticker-detail.test.tsx +3 -3
  157. package/src/plugins/builtin/world-indices/index.tsx +410 -0
  158. package/src/plugins/builtin/world-indices/indices.ts +52 -0
  159. package/src/plugins/builtin/yield-curve/index.tsx +242 -0
  160. package/src/plugins/builtin/yield-curve/treasury-data.test.ts +212 -0
  161. package/src/plugins/builtin/yield-curve/treasury-data.ts +107 -0
  162. package/src/plugins/catalog.ts +22 -0
  163. package/src/plugins/gridlock-notification.ts +15 -0
  164. package/src/plugins/ibkr/__snapshots__/trade-tab.test.tsx.snap +5 -5
  165. package/src/plugins/ibkr/index.test.tsx +1 -1
  166. package/src/plugins/ibkr/index.tsx +1 -1
  167. package/src/plugins/ibkr/trade-tab.tsx +23 -5
  168. package/src/plugins/ibkr/trade-utils.test.ts +1 -1
  169. package/src/plugins/ibkr/trade-utils.ts +7 -6
  170. package/src/plugins/ibkr/trading-pane.tsx +8 -7
  171. package/src/plugins/plugin-runtime.test.tsx +2 -0
  172. package/src/plugins/plugin-runtime.tsx +10 -0
  173. package/src/plugins/prediction-markets/controller-data.ts +8 -0
  174. package/src/plugins/prediction-markets/detail/shared.tsx +7 -6
  175. package/src/plugins/prediction-markets/plugin.test.tsx +48 -1
  176. package/src/plugins/prediction-markets/services/fetch.ts +13 -7
  177. package/src/plugins/prediction-markets/services/polymarket-adapter.ts +29 -11
  178. package/src/plugins/prediction-markets/services/polymarket-ws.ts +20 -0
  179. package/src/plugins/prediction-markets/test-helpers.tsx +2 -0
  180. package/src/plugins/registry.ts +22 -13
  181. package/src/sources/provider-router.test.ts +3 -2
  182. package/src/sources/sec-edgar.ts +13 -1
  183. package/src/sources/yahoo-finance.ts +75 -1
  184. package/src/state/app-context-selector.test.tsx +17 -1
  185. package/src/state/app-context.test.tsx +24 -0
  186. package/src/state/app-context.tsx +29 -6
  187. package/src/theme/colors.ts +5 -0
  188. package/src/theme/themes.ts +25 -0
  189. package/src/types/config.test.ts +107 -0
  190. package/src/types/config.ts +30 -1
  191. package/src/types/data-provider.ts +13 -0
  192. package/src/types/plugin.ts +35 -1
  193. package/src/utils/api-client.test.ts +90 -0
  194. package/src/utils/api-client.ts +56 -16
  195. package/src/utils/format.test.ts +11 -1
  196. package/src/utils/format.ts +86 -8
  197. package/src/utils/inline-content-tokenizer.test.ts +22 -0
  198. package/src/utils/inline-content-tokenizer.ts +76 -0
  199. package/src/utils/link-tokenizer.test.ts +27 -0
  200. package/src/utils/link-tokenizer.ts +93 -0
  201. package/src/utils/market-format.test.ts +109 -0
  202. package/src/utils/market-format.ts +299 -0
  203. package/src/utils/market-status.ts +3 -2
  204. package/src/utils/selection-clipboard.test.ts +43 -0
  205. package/src/utils/selection-clipboard.ts +88 -0
  206. package/src/utils/terminal-input-reset.test.ts +50 -0
  207. package/src/utils/terminal-input-reset.ts +24 -0
  208. package/src/utils/throttled-fetch.test.ts +145 -0
  209. package/src/utils/throttled-fetch.ts +212 -0
  210. package/src/utils/ticker-tokenizer.test.ts +31 -0
  211. package/src/utils/ticker-tokenizer.ts +7 -42
  212. package/src/version.ts +1 -1
@@ -0,0 +1,241 @@
1
+ import { spawn } from "child_process";
2
+ import type { AppNotificationRequest, AppNotificationType } from "../types/plugin";
3
+ import { debugLog } from "../utils/debug-log";
4
+
5
+ const DEFAULT_NOTIFICATION_TITLE = "Gloomberb";
6
+ const notificationLog = debugLog.createLogger("notifications");
7
+
8
+ export interface DesktopNotificationCommand {
9
+ command: string;
10
+ args: string[];
11
+ }
12
+
13
+ export interface DesktopNotificationRunner {
14
+ run(
15
+ command: string,
16
+ args: string[],
17
+ handlers?: { onError?: (error: NodeJS.ErrnoException) => void },
18
+ ): void;
19
+ }
20
+
21
+ export interface DesktopNotificationSink {
22
+ notify(notification: AppNotificationRequest): void;
23
+ }
24
+
25
+ export interface AppNotifier {
26
+ notify(notification: AppNotificationRequest): void;
27
+ }
28
+
29
+ interface CreateAppNotifierOptions {
30
+ isAppActive: () => boolean;
31
+ renderToast: (notification: AppNotificationRequest) => void;
32
+ desktop?: DesktopNotificationSink | null;
33
+ }
34
+
35
+ function escapeAppleScriptString(value: string): string {
36
+ return `"${value
37
+ .replace(/\\/g, "\\\\")
38
+ .replace(/"/g, "\\\"")}"`;
39
+ }
40
+
41
+ function escapePowerShellString(value: string): string {
42
+ return `'${value.replace(/'/g, "''")}'`;
43
+ }
44
+
45
+ function mapLinuxUrgency(type: AppNotificationType | undefined): "low" | "normal" | "critical" {
46
+ if (type === "error") return "critical";
47
+ if (type === "success") return "low";
48
+ return "normal";
49
+ }
50
+
51
+ function mapWindowsIcon(type: AppNotificationType | undefined): string {
52
+ if (type === "error") return "Error";
53
+ if (type === "success") return "Information";
54
+ return "Information";
55
+ }
56
+
57
+ function buildLinuxBody(notification: AppNotificationRequest): string | undefined {
58
+ const parts = [notification.subtitle?.trim(), notification.body.trim()].filter(Boolean);
59
+ return parts.length > 0 ? parts.join("\n") : undefined;
60
+ }
61
+
62
+ function buildWindowsBody(notification: AppNotificationRequest): string {
63
+ const parts = [notification.subtitle?.trim(), notification.body.trim()].filter(Boolean);
64
+ return parts.length > 0 ? parts.join("\n") : notification.body.trim();
65
+ }
66
+
67
+ export function buildDesktopNotificationCommand(
68
+ notification: AppNotificationRequest,
69
+ platform: NodeJS.Platform = process.platform,
70
+ ): DesktopNotificationCommand | null {
71
+ const title = notification.title?.trim() || DEFAULT_NOTIFICATION_TITLE;
72
+ const body = notification.body.trim();
73
+ const subtitle = notification.subtitle?.trim();
74
+
75
+ if (!body) {
76
+ return null;
77
+ }
78
+
79
+ if (platform === "darwin") {
80
+ const script = [
81
+ `display notification ${escapeAppleScriptString(body)} with title ${escapeAppleScriptString(title)}`,
82
+ subtitle ? `subtitle ${escapeAppleScriptString(subtitle)}` : "",
83
+ notification.sound ? `sound name ${escapeAppleScriptString(notification.sound)}` : "",
84
+ ].filter(Boolean).join(" ");
85
+ return {
86
+ command: "osascript",
87
+ args: ["-e", script],
88
+ };
89
+ }
90
+
91
+ if (platform === "linux") {
92
+ const linuxBody = buildLinuxBody(notification);
93
+ return {
94
+ command: "notify-send",
95
+ args: [
96
+ "--app-name",
97
+ DEFAULT_NOTIFICATION_TITLE,
98
+ "--urgency",
99
+ mapLinuxUrgency(notification.type),
100
+ title,
101
+ ...(linuxBody ? [linuxBody] : []),
102
+ ],
103
+ };
104
+ }
105
+
106
+ if (platform === "win32") {
107
+ const balloonBody = buildWindowsBody(notification);
108
+ const script = [
109
+ "Add-Type -AssemblyName System.Windows.Forms;",
110
+ "Add-Type -AssemblyName System.Drawing;",
111
+ "$notify = New-Object System.Windows.Forms.NotifyIcon;",
112
+ `$notify.Icon = [System.Drawing.SystemIcons]::${mapWindowsIcon(notification.type)};`,
113
+ `$notify.BalloonTipTitle = ${escapePowerShellString(title)};`,
114
+ `$notify.BalloonTipText = ${escapePowerShellString(balloonBody)};`,
115
+ "$notify.Visible = $true;",
116
+ "$notify.ShowBalloonTip(5000);",
117
+ "Start-Sleep -Seconds 6;",
118
+ "$notify.Dispose();",
119
+ ].join(" ");
120
+ return {
121
+ command: "powershell.exe",
122
+ args: ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script],
123
+ };
124
+ }
125
+
126
+ return null;
127
+ }
128
+
129
+ function defaultDesktopNotificationRunner(
130
+ command: string,
131
+ args: string[],
132
+ handlers?: { onError?: (error: NodeJS.ErrnoException) => void },
133
+ ): void {
134
+ const child = spawn(command, args, { detached: true, stdio: "ignore" });
135
+ child.once("error", (error) => {
136
+ handlers?.onError?.(error);
137
+ });
138
+ child.unref();
139
+ }
140
+
141
+ export function buildSoundCommand(
142
+ soundName: string,
143
+ platform: NodeJS.Platform = process.platform,
144
+ ): DesktopNotificationCommand | null {
145
+ if (platform === "darwin") {
146
+ return {
147
+ command: "afplay",
148
+ args: [`/System/Library/Sounds/${soundName}.aiff`],
149
+ };
150
+ }
151
+
152
+ if (platform === "linux") {
153
+ const soundFile = soundName === "Glass" ? "dialog-information"
154
+ : soundName === "Ping" ? "message-new-instant"
155
+ : soundName === "Hero" ? "dialog-warning"
156
+ : "bell";
157
+ return {
158
+ command: "paplay",
159
+ args: [`/usr/share/sounds/freedesktop/stereo/${soundFile}.oga`],
160
+ };
161
+ }
162
+
163
+ if (platform === "win32") {
164
+ return {
165
+ command: "powershell.exe",
166
+ args: ["-NoProfile", "-NonInteractive", "-Command", "[System.Media.SystemSounds]::Beep.Play()"],
167
+ };
168
+ }
169
+
170
+ return null;
171
+ }
172
+
173
+ export function createDesktopNotifier(
174
+ options: {
175
+ platform?: NodeJS.Platform;
176
+ runner?: DesktopNotificationRunner;
177
+ } = {},
178
+ ): DesktopNotificationSink {
179
+ const platform = options.platform ?? process.platform;
180
+ const runner = options.runner ?? { run: defaultDesktopNotificationRunner };
181
+ let disabledCommand: string | null = null;
182
+
183
+ return {
184
+ notify(notification) {
185
+ const desktopCommand = buildDesktopNotificationCommand(notification, platform);
186
+ if (desktopCommand && disabledCommand !== desktopCommand.command) {
187
+ runner.run(desktopCommand.command, desktopCommand.args, {
188
+ onError: (error) => {
189
+ if (error.code === "ENOENT") {
190
+ disabledCommand = desktopCommand.command;
191
+ }
192
+ notificationLog.warn("desktop notification failed", {
193
+ command: desktopCommand.command,
194
+ code: error.code,
195
+ message: error.message,
196
+ });
197
+ },
198
+ });
199
+ }
200
+
201
+ if (notification.sound) {
202
+ const soundCommand = buildSoundCommand(notification.sound, platform);
203
+ if (soundCommand) {
204
+ runner.run(soundCommand.command, soundCommand.args, {
205
+ onError: (error) => {
206
+ notificationLog.warn("sound playback failed", {
207
+ command: soundCommand.command,
208
+ code: error.code,
209
+ message: error.message,
210
+ });
211
+ },
212
+ });
213
+ }
214
+ }
215
+ },
216
+ };
217
+ }
218
+
219
+ export function createAppNotifier({
220
+ isAppActive,
221
+ renderToast,
222
+ desktop = createDesktopNotifier(),
223
+ }: CreateAppNotifierOptions): AppNotifier {
224
+ return {
225
+ notify(notification) {
226
+ const toastEnabled = notification.toast !== false;
227
+ const desktopMode = notification.desktop ?? "never";
228
+
229
+ if (toastEnabled) {
230
+ renderToast(notification);
231
+ }
232
+
233
+ if (
234
+ desktopMode === "always" ||
235
+ (desktopMode === "when-inactive" && !isAppActive())
236
+ ) {
237
+ desktop?.notify(notification);
238
+ }
239
+ },
240
+ };
241
+ }
@@ -15,6 +15,8 @@ describe("pane settings helpers", () => {
15
15
  });
16
16
  expect(portfolioPane?.settings?.columnIds).toEqual(DEFAULT_PORTFOLIO_COLUMN_IDS);
17
17
  expect(detailPane?.settings).toEqual({
18
+ chartRangePreset: "5Y",
19
+ chartResolution: "auto",
18
20
  hideTabs: false,
19
21
  lockedTabId: "overview",
20
22
  });
@@ -63,7 +63,7 @@ function createPluginContext() {
63
63
  emit: () => {},
64
64
  showWidget: () => {},
65
65
  hideWidget: () => {},
66
- showToast: () => {},
66
+ notify: () => {},
67
67
  } satisfies GloomPluginContext;
68
68
 
69
69
  return { ctx, panes, templates, detailTabs };
@@ -21,6 +21,8 @@ function makeRuntime(): PluginRuntimeAccess {
21
21
  const listeners = new Map<string, Set<() => void>>();
22
22
 
23
23
  return {
24
+ pinTicker() {},
25
+ navigateTicker() {},
24
26
  subscribeResumeState(pluginId, key, listener) {
25
27
  const storeKey = `${pluginId}:${key}`;
26
28
  if (!listeners.has(storeKey)) listeners.set(storeKey, new Set());
@@ -142,6 +142,7 @@ function ScreenerPromptEditor({
142
142
  placeholderColor={colors.textDim}
143
143
  backgroundColor={colors.panel}
144
144
  flexGrow={1}
145
+ wrapText
145
146
  />
146
147
  </box>
147
148
  );
@@ -1,4 +1,5 @@
1
1
  import { convertCurrency, formatCompact, formatCompactCurrency, formatCurrency, formatPercent } from "../../../utils/format";
2
+ import { formatMarketPriceWithCurrency } from "../../../utils/market-format";
2
3
  import type { TickerFinancials } from "../../../types/financials";
3
4
  import type { TickerRecord } from "../../../types/ticker";
4
5
 
@@ -28,9 +29,9 @@ export function buildTickerAiContext(
28
29
  if (profile?.description) lines.push(`Description: ${profile.description}`);
29
30
 
30
31
  if (quote) {
31
- lines.push(`Current Price: ${formatCurrency(quote.price, quote.currency)} (${quote.change >= 0 ? "+" : ""}${quote.changePercent.toFixed(2)}%)`);
32
+ lines.push(`Current Price: ${formatMarketPriceWithCurrency(quote.price, quote.currency, { assetCategory: metadata.assetCategory })} (${quote.change >= 0 ? "+" : ""}${quote.changePercent.toFixed(2)}%)`);
32
33
  if (quote.marketCap) lines.push(`Market Cap: ${formatCompactCurrency(toBase(quote.marketCap, quoteCurrency), baseCurrency)}`);
33
- if (quote.high52w && quote.low52w) lines.push(`52W Range: ${formatCurrency(quote.low52w, quote.currency)} - ${formatCurrency(quote.high52w, quote.currency)}`);
34
+ if (quote.high52w && quote.low52w) lines.push(`52W Range: ${formatMarketPriceWithCurrency(quote.low52w, quote.currency, { assetCategory: metadata.assetCategory })} - ${formatMarketPriceWithCurrency(quote.high52w, quote.currency, { assetCategory: metadata.assetCategory })}`);
34
35
  }
35
36
 
36
37
  if (fundamentals) {
@@ -0,0 +1,90 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { evaluateAlert, createAlert, formatAlertDescription, serializeAlerts, deserializeAlerts } from "./alert-engine";
3
+
4
+ describe("evaluateAlert", () => {
5
+ test("above: triggers when price exceeds target", () => {
6
+ const alert = createAlert("AAPL", "above", 200);
7
+ expect(evaluateAlert(alert, 199)).toBe(false);
8
+ expect(evaluateAlert(alert, 200)).toBe(false);
9
+ expect(evaluateAlert(alert, 201)).toBe(true);
10
+ });
11
+
12
+ test("below: triggers when price drops below target", () => {
13
+ const alert = createAlert("AAPL", "below", 150);
14
+ expect(evaluateAlert(alert, 151)).toBe(false);
15
+ expect(evaluateAlert(alert, 150)).toBe(false);
16
+ expect(evaluateAlert(alert, 149)).toBe(true);
17
+ });
18
+
19
+ test("crosses: triggers when price crosses target in either direction", () => {
20
+ const alert = createAlert("AAPL", "crosses", 180);
21
+ expect(evaluateAlert(alert, 175)).toBe(false);
22
+ alert.lastCheckedPrice = 175;
23
+ expect(evaluateAlert(alert, 185)).toBe(true);
24
+ });
25
+
26
+ test("crosses: triggers downward crossing", () => {
27
+ const alert = createAlert("AAPL", "crosses", 180);
28
+ alert.lastCheckedPrice = 185;
29
+ expect(evaluateAlert(alert, 175)).toBe(true);
30
+ });
31
+
32
+ test("crosses: does not trigger without prior price", () => {
33
+ const alert = createAlert("AAPL", "crosses", 180);
34
+ expect(evaluateAlert(alert, 185)).toBe(false);
35
+ });
36
+
37
+ test("does not evaluate triggered alerts", () => {
38
+ const alert = createAlert("AAPL", "above", 200);
39
+ alert.status = "triggered";
40
+ expect(evaluateAlert(alert, 999)).toBe(false);
41
+ });
42
+ });
43
+
44
+ describe("createAlert", () => {
45
+ test("creates alert with active status", () => {
46
+ const alert = createAlert("TSLA", "below", 100);
47
+ expect(alert.symbol).toBe("TSLA");
48
+ expect(alert.condition).toBe("below");
49
+ expect(alert.targetPrice).toBe(100);
50
+ expect(alert.status).toBe("active");
51
+ expect(alert.id).toBeTruthy();
52
+ });
53
+
54
+ test("uppercases symbol", () => {
55
+ expect(createAlert("aapl", "above", 200).symbol).toBe("AAPL");
56
+ });
57
+ });
58
+
59
+ describe("formatAlertDescription", () => {
60
+ test("formats above", () => {
61
+ expect(formatAlertDescription(createAlert("AAPL", "above", 200))).toBe("AAPL > 200");
62
+ });
63
+ test("formats below", () => {
64
+ expect(formatAlertDescription(createAlert("AAPL", "below", 150))).toBe("AAPL < 150");
65
+ });
66
+ test("formats crosses", () => {
67
+ expect(formatAlertDescription(createAlert("AAPL", "crosses", 180))).toBe("AAPL ↕ 180");
68
+ });
69
+ });
70
+
71
+ describe("serializeAlerts / deserializeAlerts", () => {
72
+ test("roundtrips alerts", () => {
73
+ const alerts = [createAlert("AAPL", "above", 200), createAlert("TSLA", "below", 100)];
74
+ const json = serializeAlerts(alerts);
75
+ const restored = deserializeAlerts(json);
76
+ expect(restored).toHaveLength(2);
77
+ expect(restored[0]!.symbol).toBe("AAPL");
78
+ expect(restored[1]!.symbol).toBe("TSLA");
79
+ });
80
+
81
+ test("handles invalid JSON", () => {
82
+ expect(deserializeAlerts("not json")).toEqual([]);
83
+ expect(deserializeAlerts("null")).toEqual([]);
84
+ expect(deserializeAlerts("[]")).toEqual([]);
85
+ });
86
+
87
+ test("filters invalid entries", () => {
88
+ expect(deserializeAlerts('[{"bad": true}]')).toEqual([]);
89
+ });
90
+ });
@@ -0,0 +1,55 @@
1
+ import type { AlertCondition, AlertRule } from "./types";
2
+
3
+ export type { AlertRule };
4
+
5
+ export function createAlert(symbol: string, condition: AlertCondition, targetPrice: number): AlertRule {
6
+ return {
7
+ id: `alert-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`,
8
+ symbol: symbol.toUpperCase(),
9
+ condition,
10
+ targetPrice,
11
+ createdAt: Date.now(),
12
+ status: "active",
13
+ };
14
+ }
15
+
16
+ export function evaluateAlert(alert: AlertRule, currentPrice: number): boolean {
17
+ if (alert.status !== "active") return false;
18
+
19
+ switch (alert.condition) {
20
+ case "above":
21
+ return currentPrice > alert.targetPrice;
22
+ case "below":
23
+ return currentPrice < alert.targetPrice;
24
+ case "crosses": {
25
+ if (alert.lastCheckedPrice == null) return false;
26
+ const wasBelowOrAt = alert.lastCheckedPrice <= alert.targetPrice;
27
+ const wasAboveOrAt = alert.lastCheckedPrice >= alert.targetPrice;
28
+ const isAbove = currentPrice > alert.targetPrice;
29
+ const isBelow = currentPrice < alert.targetPrice;
30
+ return (wasBelowOrAt && isAbove) || (wasAboveOrAt && isBelow);
31
+ }
32
+ }
33
+ }
34
+
35
+ export function formatAlertDescription(alert: AlertRule): string {
36
+ const prefix = alert.condition === "above" ? ">"
37
+ : alert.condition === "below" ? "<" : "↕";
38
+ return `${alert.symbol} ${prefix} ${alert.targetPrice}`;
39
+ }
40
+
41
+ export function serializeAlerts(alerts: AlertRule[]): string {
42
+ return JSON.stringify(alerts);
43
+ }
44
+
45
+ export function deserializeAlerts(json: string): AlertRule[] {
46
+ try {
47
+ const parsed = JSON.parse(json);
48
+ if (!Array.isArray(parsed)) return [];
49
+ return parsed.filter((a: any) =>
50
+ a?.id && a?.symbol && a?.condition && typeof a?.targetPrice === "number"
51
+ );
52
+ } catch {
53
+ return [];
54
+ }
55
+ }