@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.
Files changed (209) hide show
  1. package/LICENSE +0 -4
  2. package/package.json +6 -5
  3. package/patches/electrobun-devkit@2.0.5.patch +408 -0
  4. package/src/api-client/bond-trades.ts +59 -0
  5. package/src/api-client/crypto-markets.ts +20 -2
  6. package/src/api-client/data.ts +21 -0
  7. package/src/api-client/fund-facts.ts +23 -1
  8. package/src/api-client/index.ts +2 -0
  9. package/src/api-client/types/account.ts +86 -0
  10. package/src/api-client/types/assist.ts +32 -0
  11. package/src/api-client/types/auth.ts +63 -0
  12. package/src/api-client/types/billing.ts +54 -0
  13. package/src/api-client/types/chat.ts +180 -0
  14. package/src/api-client/types/congress.ts +107 -0
  15. package/src/api-client/types/credit.ts +110 -0
  16. package/src/api-client/types/econ.ts +158 -0
  17. package/src/api-client/types/equity-diagnostic.ts +73 -0
  18. package/src/api-client/types/filings-and-calls.ts +356 -0
  19. package/src/api-client/types/index.ts +25 -0
  20. package/src/api-client/types/jobs.ts +147 -0
  21. package/src/api-client/types/market.ts +122 -0
  22. package/src/api-client/types/news.ts +91 -0
  23. package/src/api-client/types/notes-and-theses.ts +172 -0
  24. package/src/api-client/types/quotes.ts +28 -0
  25. package/src/api-client/types/scanners.ts +125 -0
  26. package/src/api-client/types/screener.ts +65 -0
  27. package/src/api-client/types/search.ts +107 -0
  28. package/src/api-client/types/sync.ts +14 -0
  29. package/src/api-client/types/team-collections.ts +43 -0
  30. package/src/api-client/types/team-views.ts +32 -0
  31. package/src/api-client/types/teams.ts +135 -0
  32. package/src/api-client/types/ticker-data.ts +57 -0
  33. package/src/api-client/types/tweets.ts +59 -0
  34. package/src/api-client/types/world-venues.ts +23 -0
  35. package/src/app/runtime/desktop-deeplink.ts +41 -6
  36. package/src/app/runtime/plugin-seed.ts +119 -0
  37. package/src/app/runtime/startup.ts +45 -9
  38. package/src/app/star-prompt/status-line.tsx +1 -1
  39. package/src/app.tsx +2 -7
  40. package/src/architecture/ui-tokens-allowlist.json +0 -8
  41. package/src/cli/board-coins.ts +38 -5
  42. package/src/cli/commands/crypto-hints.ts +8 -1
  43. package/src/cli/commands/market.ts +29 -26
  44. package/src/cli/commands/overview.ts +13 -6
  45. package/src/cli/commands/ticker.ts +78 -18
  46. package/src/cli/company-name-hint.ts +19 -0
  47. package/src/cli/desktop-pane-shot-browser.ts +69 -3
  48. package/src/cli/entry.ts +10 -4
  49. package/src/cli/glossary.ts +25 -0
  50. package/src/cli/helpers.ts +4 -2
  51. package/src/cli/not-a-ticker.ts +26 -1
  52. package/src/cli/pane-functions/catalog.ts +3 -1
  53. package/src/cli/pane-functions/freshness.ts +45 -29
  54. package/src/cli/pane-functions/market-session.ts +14 -5
  55. package/src/cli/restore-plugins.ts +164 -51
  56. package/src/components/chart/composite/use-composite-chart-keyboard.ts +11 -2
  57. package/src/components/chart-table/header.tsx +10 -1
  58. package/src/components/chart-table/layout.ts +14 -5
  59. package/src/components/command-bar/panel/index.tsx +13 -0
  60. package/src/components/command-bar/panel/layout.ts +7 -0
  61. package/src/components/command-bar/panel/runtime.ts +1 -0
  62. package/src/components/command-bar/panel/types.ts +2 -0
  63. package/src/components/data-table/export.ts +4 -1
  64. package/src/components/layout/detached-pane-shell.tsx +10 -37
  65. package/src/components/layout/double-escape-close.ts +90 -0
  66. package/src/components/layout/header.tsx +3 -2
  67. package/src/components/layout/market-summary.ts +6 -3
  68. package/src/components/layout/pane/footer/index.tsx +2 -6
  69. package/src/components/layout/pane/footer/model.ts +6 -12
  70. package/src/components/layout/shell/active-drag.ts +53 -11
  71. package/src/components/layout/shell/drag/magnets.ts +128 -19
  72. package/src/components/layout/shell/pane/actions.ts +6 -2
  73. package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
  74. package/src/components/layout/status-bar.tsx +4 -78
  75. package/src/components/layout/status-widget-space.ts +5 -5
  76. package/src/components/onboarding/portfolio-step/positions-panel.tsx +1 -1
  77. package/src/components/ui/data-table/index.tsx +5 -1
  78. package/src/components/ui/data-table/render-cell.ts +19 -0
  79. package/src/components/ui/delayed-mark.tsx +59 -7
  80. package/src/components/ui/icon.tsx +1 -8
  81. package/src/components/ui/menu.tsx +6 -1
  82. package/src/i18n/es.ts +6 -3
  83. package/src/i18n/ja.ts +6 -3
  84. package/src/i18n/ko.ts +6 -3
  85. package/src/i18n/zh-cn.ts +6 -3
  86. package/src/i18n/zh-tw.ts +6 -3
  87. package/src/market-data/fund-facts.ts +7 -1
  88. package/src/market-data/market/change-basis.ts +20 -0
  89. package/src/market-data/market/format.ts +62 -2
  90. package/src/market-data/market/futures-week.ts +3 -1
  91. package/src/plugins/builtin/chart-composer/headless.ts +57 -17
  92. package/src/plugins/builtin/chart-composer/session-range.ts +82 -3
  93. package/src/plugins/builtin/chat/content/composer.tsx +21 -27
  94. package/src/plugins/builtin/chat/content/index.tsx +31 -3
  95. package/src/plugins/builtin/chat/content/shortcuts.ts +4 -2
  96. package/src/plugins/builtin/chat/content/snapshot.ts +0 -3
  97. package/src/plugins/builtin/cloud/auth-actions.tsx +51 -23
  98. package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +3 -3
  99. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +32 -25
  100. package/src/plugins/builtin/congress-trades/model.ts +2 -1
  101. package/src/plugins/builtin/congress-trades/pane.tsx +3 -0
  102. package/src/plugins/builtin/correlation/compute.ts +8 -2
  103. package/src/plugins/builtin/correlation/headless.ts +10 -9
  104. package/src/plugins/builtin/correlation/history.ts +30 -0
  105. package/src/plugins/builtin/correlation/matrix/model.ts +10 -10
  106. package/src/plugins/builtin/correlation/relationship/model.ts +3 -6
  107. package/src/plugins/builtin/correlation/relationship/pane.tsx +1 -2
  108. package/src/plugins/builtin/crypto-board/client.ts +6 -1
  109. package/src/plugins/builtin/crypto-board/defi-view.tsx +12 -1
  110. package/src/plugins/builtin/crypto-board/defi.ts +44 -7
  111. package/src/plugins/builtin/crypto-board/headless.ts +83 -12
  112. package/src/plugins/builtin/crypto-board/model.ts +30 -6
  113. package/src/plugins/builtin/crypto-board/pane.tsx +13 -2
  114. package/src/plugins/builtin/custom-view/index.tsx +1 -1
  115. package/src/plugins/builtin/custom-view/loader.ts +85 -8
  116. package/src/plugins/builtin/custom-view/view-spec.ts +28 -0
  117. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +13 -4
  118. package/src/plugins/builtin/equity-screener/headless.ts +33 -1
  119. package/src/plugins/builtin/equity-screener/model.ts +58 -15
  120. package/src/plugins/builtin/equity-screener/pane.tsx +36 -6
  121. package/src/plugins/builtin/executives/format.ts +5 -4
  122. package/src/plugins/builtin/executives/pane.tsx +1 -1
  123. package/src/plugins/builtin/help/index.tsx +55 -1
  124. package/src/plugins/builtin/insider/model.ts +30 -2
  125. package/src/plugins/builtin/jobs/model.ts +2 -2
  126. package/src/plugins/builtin/mna/model.ts +2 -2
  127. package/src/plugins/builtin/notes/files.ts +2 -0
  128. package/src/plugins/builtin/notes/owner.tsx +20 -1
  129. package/src/plugins/builtin/notes/quick-notes-pane.tsx +22 -4
  130. package/src/plugins/builtin/notes/store.ts +6 -1
  131. package/src/plugins/builtin/perps/headless.ts +8 -2
  132. package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
  133. package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
  134. package/src/plugins/builtin/risk-factors/index.tsx +2 -28
  135. package/src/plugins/builtin/risk-factors/lock-note.ts +58 -0
  136. package/src/plugins/builtin/risk-factors/pane.tsx +10 -3
  137. package/src/plugins/builtin/scanner/hilo-model.ts +4 -3
  138. package/src/plugins/builtin/sec/fund-facts.ts +45 -11
  139. package/src/plugins/builtin/sec/headless.ts +30 -1
  140. package/src/plugins/builtin/sec/index.tsx +26 -5
  141. package/src/plugins/builtin/series-inventory.ts +1 -0
  142. package/src/plugins/builtin/shared/earnings-report.ts +7 -2
  143. package/src/plugins/builtin/shared/pro-lock-note.ts +5 -1
  144. package/src/plugins/builtin/shared/use-quote-board.ts +85 -46
  145. package/src/plugins/builtin/short-interest/headless.ts +1 -1
  146. package/src/plugins/builtin/short-interest/model.ts +15 -6
  147. package/src/plugins/builtin/short-interest/types.ts +2 -0
  148. package/src/plugins/builtin/thirteenf/overlap-pane.tsx +3 -0
  149. package/src/plugins/builtin/thirteenf/pane.tsx +3 -0
  150. package/src/plugins/builtin/ticker-detail/overview/model.ts +19 -9
  151. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
  152. package/src/plugins/builtin/time-sales/headless.ts +23 -7
  153. package/src/plugins/builtin/time-sales/index.tsx +2 -2
  154. package/src/plugins/builtin/trace-bonds/detail.tsx +198 -0
  155. package/src/plugins/builtin/trace-bonds/headless.ts +62 -4
  156. package/src/plugins/builtin/trace-bonds/history.ts +155 -0
  157. package/src/plugins/builtin/trace-bonds/pane.tsx +64 -5
  158. package/src/plugins/extracted-plugins.ts +49 -24
  159. package/src/plugins/installer.ts +234 -32
  160. package/src/plugins/plugin-names.ts +11 -2
  161. package/src/plugins/running-installs.ts +34 -0
  162. package/src/plugins/seed-progress.ts +72 -0
  163. package/src/remote/controller.ts +9 -2
  164. package/src/remote/schema.ts +2 -1
  165. package/src/renderers/cloudflare/http-proxy.ts +67 -8
  166. package/src/renderers/cloudflare/proxy-session.ts +1 -1
  167. package/src/renderers/cloudflare/worker.ts +29 -2
  168. package/src/renderers/dom/desktop/icons.tsx +0 -2
  169. package/src/renderers/dom/styles.css +0 -3
  170. package/src/renderers/electrobun/bun/desktop/backend.ts +14 -0
  171. package/src/renderers/electrobun/bun/desktop/host-requests.ts +14 -7
  172. package/src/renderers/electrobun/bun/desktop/initialization.ts +24 -14
  173. package/src/renderers/electrobun/bun/desktop/install-records.ts +59 -0
  174. package/src/renderers/electrobun/bun/desktop/installer-folder.ts +208 -592
  175. package/src/renderers/electrobun/bun/desktop/macos-objc.ts +14 -0
  176. package/src/renderers/electrobun/bun/desktop/update.ts +1 -1
  177. package/src/renderers/electrobun/bun/index.ts +24 -13
  178. package/src/renderers/electrobun/bun/window/context-menu-thread.ts +84 -0
  179. package/src/renderers/electrobun/bun/window/create.ts +23 -3
  180. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +4 -4
  181. package/src/renderers/electrobun/bun/window/events.ts +4 -4
  182. package/src/renderers/electrobun/bun/window/frame.ts +2 -1
  183. package/src/renderers/electrobun/bun/window/native-call-thread.ts +224 -0
  184. package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
  185. package/src/renderers/electrobun/bun/window/native-timing.ts +10 -0
  186. package/src/renderers/electrobun/bun/window/script-for-webview.ts +15 -0
  187. package/src/renderers/electrobun/bun/window/webview-script-thread.ts +82 -0
  188. package/src/renderers/electrobun/shared/protocol.ts +13 -2
  189. package/src/renderers/electrobun/view/backend-rpc.ts +8 -1
  190. package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +1 -1
  191. package/src/renderers/electrobun/view/main.tsx +4 -3
  192. package/src/renderers/opentui/start.tsx +3 -0
  193. package/src/sources/gloomberb-cloud/index.ts +5 -7
  194. package/src/sources/provider-router/batches.ts +18 -3
  195. package/src/sources/provider-router/financials.ts +18 -4
  196. package/src/telemetry/stall-reports.ts +21 -4
  197. package/src/types/data-provider.ts +14 -0
  198. package/src/types/financials.ts +15 -3
  199. package/src/types/headless.ts +2 -0
  200. package/src/utils/double-escape-close.ts +38 -16
  201. package/src/utils/format.ts +23 -3
  202. package/src/utils/main-thread-stall.ts +21 -5
  203. package/src/utils/perf-marks.ts +88 -9
  204. package/src/utils/price-earnings.ts +18 -0
  205. package/src/utils/reported-money.ts +9 -2
  206. package/src/utils/sec.ts +34 -3
  207. package/patches/electrobun@1.18.1.patch +0 -633
  208. package/src/api-client/types.ts +0 -2441
  209. package/src/plugins/seed-notice.ts +0 -20
@@ -5,7 +5,7 @@ import type { AppConfig } from "../../../types/config";
5
5
  import { getSharedRegistry, type PluginRegistry } from "../../registry";
6
6
  import { marketContextFromRegistry } from "../cloud/askg/host";
7
7
  import { notViewSourceMessage, unknownViewSourceMessage } from "./sources";
8
- import type { ViewRow, ViewSource, ViewSpec } from "./view-spec";
8
+ import { applyViewProjection, unknownViewKeys, type UnknownViewKey, type ViewKeyPlace, type ViewRow, type ViewSource, type ViewSpec } from "./view-spec";
9
9
 
10
10
  export interface LoadedView {
11
11
  rows: ViewRow[];
@@ -113,14 +113,93 @@ export async function loadViewSource(
113
113
 
114
114
  /** How long a trial load waits; under the 10 s a remote tool call is given. */
115
115
  const VIEW_TRIAL_TIMEOUT_MS = 8_000;
116
+ /** Source keys a refusal lists at most. */
117
+ const LISTED_SOURCE_KEYS = 60;
118
+
119
+ /** The spec names keys the source's rows never carry; nothing is kept. */
120
+ export class UnknownViewKeysError extends Error {
121
+ override name = "UnknownViewKeysError";
122
+ }
123
+
124
+ const PLACE_NAMES: Record<ViewKeyPlace, [one: string, many: string]> = {
125
+ column: ["column", "columns"],
126
+ filter: ["filter key", "filter keys"],
127
+ sort: ["sort key", "sort keys"],
128
+ symbolKey: ["symbol key", "symbol keys"],
129
+ };
130
+
131
+ /** `columns change1d, low30d; sort key vol` */
132
+ function describeUnknownKeys(unknown: readonly UnknownViewKey[]): string {
133
+ const byPlace = new Map<ViewKeyPlace, string[]>();
134
+ for (const { key, place } of unknown) byPlace.set(place, [...(byPlace.get(place) ?? []), key]);
135
+ return [...byPlace].map(([place, keys]) => `${PLACE_NAMES[place][keys.length === 1 ? 0 : 1]} ${keys.join(", ")}`).join("; ");
136
+ }
137
+
138
+ function comparable(text: string): string {
139
+ return text.toLowerCase().replace(/[^a-z0-9]/g, "");
140
+ }
141
+
142
+ /** The source's keys, its listed columns first with their header where it says more than the key: `title (Market)`. */
143
+ function describeSourceKeys(columns: readonly HeadlessPaneColumn[], rowKeys: Iterable<string>): string {
144
+ const entries = new Map<string, string>();
145
+ for (const column of columns) {
146
+ if (entries.has(column.key)) continue;
147
+ const header = column.header?.trim();
148
+ entries.set(column.key, header && comparable(header) !== comparable(column.key) ? `${column.key} (${header})` : column.key);
149
+ }
150
+ for (const key of rowKeys) if (!entries.has(key)) entries.set(key, key);
151
+ const listed = [...entries.values()];
152
+ const more = listed.length - LISTED_SOURCE_KEYS;
153
+ return more > 0 ? `${listed.slice(0, LISTED_SOURCE_KEYS).join(", ")} and ${more} more` : listed.join(", ");
154
+ }
155
+
156
+ /**
157
+ * What a trial load says about the spec. Names the spec uses that none of the
158
+ * loaded rows carry throw `UnknownViewKeysError` with the keys they do carry,
159
+ * so a view never opens on columns that stay blank or filters that drop every
160
+ * row. With no rows to read, the source's listed columns are all there is to
161
+ * check against and they need not list every key, so a mismatch only warns.
162
+ */
163
+ function checkLoadedView(spec: ViewSpec, loaded: LoadedView): string[] {
164
+ const notes = loaded.errors.slice(0, 2);
165
+ const listed = new Set(loaded.columns.map((column) => column.key));
166
+ if (loaded.rows.length === 0) {
167
+ const unlisted = listed.size > 0 ? unknownViewKeys(spec, listed) : [];
168
+ return [
169
+ "The source loaded no rows.",
170
+ ...notes,
171
+ ...(unlisted.length > 0
172
+ ? [`With no rows to check, these are not among the ${loaded.sourceLabel} columns: ${describeUnknownKeys(unlisted)}. Its columns: ${describeSourceKeys(loaded.columns, [])}.`]
173
+ : []),
174
+ ];
175
+ }
176
+ const rowKeys = new Set<string>();
177
+ for (const row of loaded.rows) for (const key of Object.keys(row)) rowKeys.add(key);
178
+ const unknown = unknownViewKeys(spec, new Set([...listed, ...rowKeys]));
179
+ if (unknown.length > 0) {
180
+ throw new UnknownViewKeysError(
181
+ `Not in the ${loaded.sourceLabel} rows: ${describeUnknownKeys(unknown)}. `
182
+ + `Its rows carry: ${describeSourceKeys(loaded.columns, rowKeys)}. `
183
+ + "Use only those keys, and say which of the asked-for columns this source does not have.",
184
+ );
185
+ }
186
+ const { filters } = spec.projection;
187
+ if (filters.length > 0 && applyViewProjection(loaded.rows, { columns: [], filters }, null).length === 0) {
188
+ const count = loaded.rows.length;
189
+ const none = count === 1 ? "The one row the source loaded does not pass" : `None of the ${count} rows the source loaded pass`;
190
+ return [`${none} the view's filters, so the view shows no rows.`, ...notes];
191
+ }
192
+ return notes;
193
+ }
116
194
 
117
195
  /**
118
196
  * Loads the spec's source once through `loadViewSource`, the path its pane
119
197
  * takes, before the spec is kept. Throws what the source throws (an unknown
120
- * function with the valid ones, a usage or option error, a failed read), so
121
- * nothing broken is saved. Resolves with what to tell the person: notes the
122
- * source carried, an empty result, or that it had not answered in time, which
123
- * is not a failure: a slow source still opens.
198
+ * function with the valid ones, a usage or option error, a failed read), or
199
+ * `UnknownViewKeysError` for keys its rows never carry, so nothing broken is
200
+ * saved. Resolves with what to tell the person: notes the source carried, an
201
+ * empty result, or that it had not answered in time, which is not a failure:
202
+ * a slow source still opens.
124
203
  */
125
204
  export async function trialLoadViewSource(
126
205
  spec: ViewSpec,
@@ -148,9 +227,7 @@ export async function trialLoadViewSource(
148
227
  if (outcome === "timeout") {
149
228
  return [`The source had not answered after ${Math.max(1, Math.round(timeoutMs / 1_000))} s, so it was not checked. The view opens and keeps loading.`];
150
229
  }
151
- return outcome.rows.length === 0
152
- ? ["The source loaded no rows.", ...outcome.errors.slice(0, 2)]
153
- : outcome.errors.slice(0, 2);
230
+ return checkLoadedView(spec, outcome);
154
231
  } finally {
155
232
  clearTimeout(timer);
156
233
  signal?.removeEventListener("abort", abort);
@@ -297,6 +297,34 @@ export function parseViewSpecOr(value: unknown): { spec: ViewSpec; result: ViewS
297
297
  return { spec, result };
298
298
  }
299
299
 
300
+ /** Where a spec names a row key. */
301
+ export type ViewKeyPlace = "column" | "filter" | "sort" | "symbolKey";
302
+
303
+ export interface UnknownViewKey {
304
+ key: string;
305
+ place: ViewKeyPlace;
306
+ }
307
+
308
+ /**
309
+ * The row keys the spec's columns, filters, sort and symbol key name that are
310
+ * not in `known`, once per place, in the spec's order. A key no row carries
311
+ * leaves a column blank, and a filter or sort on it drops or scrambles every row.
312
+ */
313
+ export function unknownViewKeys(spec: ViewSpec, known: ReadonlySet<string>): UnknownViewKey[] {
314
+ const unknown: UnknownViewKey[] = [];
315
+ const seen = new Set<string>();
316
+ const check = (key: string, place: ViewKeyPlace) => {
317
+ if (known.has(key) || seen.has(`${place}:${key}`)) return;
318
+ seen.add(`${place}:${key}`);
319
+ unknown.push({ key, place });
320
+ };
321
+ for (const column of spec.projection.columns) check(column.key, "column");
322
+ for (const filter of spec.projection.filters) check(filter.key, "filter");
323
+ if (spec.projection.sort) check(spec.projection.sort.by, "sort");
324
+ if (spec.presentation.symbolKey) check(spec.presentation.symbolKey, "symbolKey");
325
+ return unknown;
326
+ }
327
+
300
328
  export function serializeViewSpec(spec: ViewSpec): string {
301
329
  const result = validateViewSpec(spec);
302
330
  if (!result.valid) throw new Error(result.errors.map((entry) => entry.message).join(" "));
@@ -13,7 +13,7 @@ import type {
13
13
  ScreenFieldDefinition,
14
14
  ScreenOperator,
15
15
  } from "../../../api-client/equity-screener";
16
- import { criterionInputText, criterionValueHint, criterionValueLabel, parseCriterion } from "./model";
16
+ import { criterionInputText, criterionValueHint, criterionValueLabel, parseCriterion, typedListName } from "./model";
17
17
 
18
18
  export function CriterionEditor({
19
19
  fields,
@@ -22,10 +22,14 @@ export function CriterionEditor({
22
22
  onCancel,
23
23
  focused,
24
24
  width,
25
+ readWatchlist,
25
26
  }: {
26
27
  fields: ScreenFieldDefinition[];
27
28
  value: ScreenCriterion | null;
28
- onSave: (criterion: ScreenCriterion) => void;
29
+ /** One name typed for the symbol field, read as that watchlist's symbols with the note saying so, or null. */
30
+ readWatchlist?: (typed: string) => { symbols: readonly string[]; note: string } | null;
31
+ /** `note` says how a watchlist's name was read, as `fn EQS` says it. */
32
+ onSave: (criterion: ScreenCriterion, note: string | null) => void;
29
33
  onCancel: () => void;
30
34
  focused: boolean;
31
35
  width: number;
@@ -52,9 +56,12 @@ export function CriterionEditor({
52
56
  "save",
53
57
  "cancel",
54
58
  ];
59
+ // A watchlist's name typed for the symbol list: what it reads as, before Save.
60
+ const listName = typedListName(field.id, operator, text);
61
+ const watchlistRead = listName ? readWatchlist?.(listName) ?? null : null;
55
62
  const save = () => {
56
63
  try {
57
- onSave(parseCriterion(field, operator, text));
64
+ onSave(parseCriterion(field, operator, text, readWatchlist), watchlistRead?.note ?? null);
58
65
  } catch (error) {
59
66
  setError(error instanceof Error ? error.message : "Invalid criterion.");
60
67
  }
@@ -142,7 +149,9 @@ export function CriterionEditor({
142
149
  onSubmit={save}
143
150
  />
144
151
  ) : null}
145
- {error ? <Notice tone="negative">{error}</Notice> : null}
152
+ {error ? <Notice tone="negative">{error}</Notice>
153
+ : watchlistRead ? <Notice tone="muted">{watchlistRead.note}</Notice>
154
+ : null}
146
155
  <Box flexDirection="row" gap={1}>
147
156
  <Button
148
157
  label="Save criterion"
@@ -25,17 +25,21 @@ import {
25
25
  unmatchedCategoryValues,
26
26
  } from "./categories";
27
27
  import { REPORT_ROWS } from "../shared/headless-options";
28
+ import { findNamedCollection, readWatchlistArgument } from "../../../portfolio/collection-name";
28
29
  import {
29
30
  appendScreenPage,
30
31
  DEFAULT_SCREEN,
31
32
  EXAMPLE_SCREEN_DEFINITION,
32
33
  formatScreenMetric,
34
+ WATCHLIST_SCREEN_DEFINITION,
35
+ MAX_SYMBOL_VALUES,
33
36
  metricDate,
34
37
  parseScreenDefinition,
35
38
  screenColumnLabel,
36
39
  screenDefinitionSyntax,
37
40
  screenCurrencyEmpty,
38
41
  screenLabel,
42
+ screenSymbols,
39
43
  screenYtdBase,
40
44
  withheldMetricNote,
41
45
  } from "./model";
@@ -45,6 +49,30 @@ import type { ScreenDefinition } from "../../../api-client/equity-screener";
45
49
  const spacedJson = (definition: ScreenDefinition) =>
46
50
  JSON.stringify(definition).replace(/([,:])(?=["{[\d-])/g, "$1 ");
47
51
 
52
+ /**
53
+ * A symbol criterion whose one value names a watchlist (`"value": ["HY3"]`)
54
+ * reads as the watchlist's symbols, at most a screen's 500, with the note
55
+ * that says so; any other criterion is left as it is.
56
+ */
57
+ async function withWatchlistSymbols(
58
+ definition: ScreenDefinition,
59
+ ctx: Pick<HeadlessPaneContext, "config" | "resolveWatchlist">,
60
+ ): Promise<{ definition: ScreenDefinition; notes: string[] }> {
61
+ const notes: string[] = [];
62
+ const criteria = await Promise.all(definition.criteria.map(async (criterion) => {
63
+ if (criterion.field !== "symbol" || criterion.op !== "in" || criterion.value.length !== 1) return criterion;
64
+ const typed = criterion.value[0]!;
65
+ const watchlist = findNamedCollection(ctx.config.watchlists, typed);
66
+ if (!watchlist || !ctx.resolveWatchlist) return criterion;
67
+ const members = screenSymbols(((await ctx.resolveWatchlist(typed)) ?? []).map((ticker) => ticker.metadata.ticker));
68
+ if (members.length === 0) return criterion;
69
+ const read = readWatchlistArgument(typed, watchlist, members, MAX_SYMBOL_VALUES);
70
+ notes.push(read.note);
71
+ return { ...criterion, value: read.symbols };
72
+ }));
73
+ return notes.length ? { definition: { ...definition, criteria }, notes } : { definition, notes };
74
+ }
75
+
48
76
  /** The `--definition` value of the catalog's worked example, quoted for a shell. */
49
77
  const EXAMPLE_DEFINITION_OPTION = `--definition '${spacedJson(EXAMPLE_SCREEN_DEFINITION)}'`;
50
78
 
@@ -207,6 +235,7 @@ export const equityScreenerHeadless: HeadlessPaneDefinition<"bundle"> = {
207
235
  placeholder: "json",
208
236
  description: screenDefinitionSyntax(),
209
237
  example: EXAMPLE_DEFINITION_OPTION,
238
+ examples: [`--definition '${spacedJson(WATCHLIST_SCREEN_DEFINITION)}'`],
210
239
  normalize: (value) => {
211
240
  readDefinition(value);
212
241
  return value;
@@ -275,12 +304,15 @@ export const equityScreenerHeadless: HeadlessPaneDefinition<"bundle"> = {
275
304
  definition = matches[0]!.definition;
276
305
  savedName = matches[0]!.name;
277
306
  }
307
+ const watchlistRead = await withWatchlistSymbols(definition, ctx);
308
+ definition = watchlistRead.definition;
278
309
  if (args.options.check) {
279
310
  const data = await fetchScreenCheck(definition, String(args.options.check), undefined, ctx.signal, ctx.apiClient);
280
311
  return {
281
312
  freshness: { asOf: data.snapshot.assembledAt },
282
313
  complete: data.status === "available" && data.warnings.length === 0,
283
314
  errors: data.warnings,
315
+ ...(watchlistRead.notes.length ? { notes: watchlistRead.notes } : {}),
284
316
  sections: data.criteria.length === 0 ? [{
285
317
  title: data.row ? `${data.row.symbol}:${data.row.exchange}` : data.symbol,
286
318
  entries: [{ label: "Result", value: screenCheckSummary(data) }],
@@ -338,7 +370,7 @@ export const equityScreenerHeadless: HeadlessPaneDefinition<"bundle"> = {
338
370
  const extra = extraScreenColumns(metrics, data.definition.sort.field);
339
371
  const states = new Set(rows.map((row) => row.metrics[metric].state));
340
372
  const legend = STATE_LEGEND.filter(({ state }) => states.has(state)).map(({ text }) => text);
341
- const notes = [...kpiGaps, ...legend];
373
+ const notes = [...watchlistRead.notes, ...kpiGaps, ...legend];
342
374
  // Payload status also counts ordinary per-field sparsity; only generation
343
375
  // warnings are failures, and more pages are not an error.
344
376
  return {
@@ -26,7 +26,7 @@ import {
26
26
  type ScreenRow,
27
27
  } from "../../../api-client/equity-screener";
28
28
  import { yearToDateBaseLabel } from "../../../market-data/market/year-to-date";
29
- import { canonicalExchange } from "../../../utils/exchanges";
29
+ import { canonicalExchange, parsePublicTickerKey } from "../../../utils/exchanges";
30
30
  import { LATEST_DISTRIBUTION, TRAILING_DIVIDEND_BASIS } from "../../../utils/forward-dividend";
31
31
  import { formatCompact, formatNumber } from "../../../utils/format";
32
32
  import { formatPriceEarnings, NOT_MEANINGFUL } from "../../../utils/price-earnings";
@@ -529,26 +529,52 @@ export const screenLabel = (field: string) =>
529
529
  field
530
530
  .replace(/([A-Z])/g, " $1")
531
531
  .replace(/^./, (value) => value.toUpperCase());
532
+ /** A category's `in` alternatives. */
533
+ const MAX_CATEGORY_VALUES = 25;
534
+ /** A list of symbols is a watchlist or a pasted list, so it takes up to 500 names. */
535
+ export const MAX_SYMBOL_VALUES = 500;
536
+ const maxCategoryValues = (field: string) => (field === "symbol" ? MAX_SYMBOL_VALUES : MAX_CATEGORY_VALUES);
537
+
538
+ /** A watchlist's tickers as a screen's symbols: each without its venue (`SAP:XETRA` is SAP), once. */
539
+ export function screenSymbols(tickers: readonly string[]): string[] {
540
+ return [...new Set(tickers.map((ticker) => parsePublicTickerKey(ticker).symbol).filter(Boolean))];
541
+ }
542
+
543
+ /** The one name typed for a symbol list, which may name a watchlist (`HY3`), or null. */
544
+ export function typedListName(fieldId: string, operator: ScreenOperator, text: string): string | null {
545
+ if (fieldId !== "symbol" || operator !== "in") return null;
546
+ const typed = text.split(",").map((value) => value.trim()).filter(Boolean);
547
+ return typed.length === 1 ? typed[0]! : null;
548
+ }
549
+
550
+ /**
551
+ * A criterion as the editor's fields give it. `readWatchlist` reads one name
552
+ * typed for the symbol field as that watchlist's symbols (`HY3`), or null
553
+ * when it names none.
554
+ */
532
555
  export function parseCriterion(
533
556
  field: ScreenFieldDefinition,
534
557
  operator: ScreenOperator,
535
558
  text: string,
559
+ readWatchlist?: (typed: string) => { symbols: readonly string[] } | null,
536
560
  ): ScreenCriterion {
537
561
  if (!field.operators.includes(operator))
538
562
  throw new Error("Choose a supported operator for this field.");
539
563
  if (operator === "present" || operator === "missing")
540
564
  return { field: field.id, op: operator };
541
565
  if (field.kind === "category") {
542
- const values = [
543
- ...new Set(
544
- text
545
- .split(",")
546
- .map((value) => value.trim())
547
- .filter(Boolean),
548
- ),
549
- ];
550
- if (operator !== "in" || !values.length || values.length > 25 || values.some((value) => value.length > 120))
551
- throw new Error("Enter 1-25 comma-separated values, up to 120 characters each.");
566
+ const typed = text
567
+ .split(",")
568
+ .map((value) => value.trim())
569
+ .filter(Boolean);
570
+ const name = typedListName(field.id, operator, text);
571
+ const listed = name ? readWatchlist?.(name)?.symbols ?? null : null;
572
+ const values = [...new Set(listed ?? typed)];
573
+ const maximum = maxCategoryValues(field.id);
574
+ if (operator !== "in" || !values.length || values.length > maximum || values.some((value) => value.length > 120))
575
+ throw new Error(field.id === "symbol"
576
+ ? `Enter a watchlist name or 1-${maximum} comma-separated symbols, up to 120 characters each.`
577
+ : `Enter 1-${maximum} comma-separated values, up to 120 characters each.`);
552
578
  return {
553
579
  field: field.id as (typeof CATEGORY_FIELDS)[number],
554
580
  op: "in",
@@ -606,6 +632,7 @@ export function criterionValueLabel(field: Pick<ScreenFieldDefinition, "id" | "u
606
632
  export function criterionValueHint(field: Pick<ScreenFieldDefinition, "id">, operator: ScreenOperator): string {
607
633
  if (LETTER_GRADES.has(field.id as NumericField)) return operator === "between" ? "lowest, highest grade, e.g. B, A+" : "grade, e.g. B+";
608
634
  if (field.id === "gradeComposite") return operator === "between" ? "minimum, maximum, e.g. 3.5, 5" : "score or label, e.g. 3.5 or Strong";
635
+ if (field.id === "symbol" && operator === "in") return "a watchlist's name or symbols, e.g. AAPL, MSFT";
609
636
  return operator === "between" ? "minimum, maximum" : operator === "in" ? "comma-separated values" : "threshold, e.g. 25 or 10B";
610
637
  }
611
638
  const SCALE: Record<string, number> = { k: 1e3, m: 1e6, b: 1e9, t: 1e12 };
@@ -619,6 +646,13 @@ export function parseThreshold(text: string): number | null {
619
646
  const thresholdText = (value: number) =>
620
647
  Math.abs(value) >= 1e6 ? formatCompact(value) : String(value);
621
648
 
649
+ /** A list past a category's length names its first values and counts the rest: a watchlist's 300 symbols do not fill a line. */
650
+ function listText(items: readonly string[]): string {
651
+ return items.length > MAX_CATEGORY_VALUES
652
+ ? `${items.slice(0, 8).join(", ")} and ${items.length - 8} more`
653
+ : items.join(", ");
654
+ }
655
+
622
656
  export function criterionText(criterion: ScreenCriterion): string {
623
657
  const symbols = {
624
658
  gte: ">=",
@@ -643,7 +677,7 @@ export function criterionText(criterion: ScreenCriterion): string {
643
677
  : criterion.field === "gradeComposite" && typeof criterion.value === "number"
644
678
  ? ` ${thresholdText(criterion.value)}${COMPOSITE_BANDS.some((band) => band.from === criterion.value && band.from > 1) ? ` (${compositeLabel(criterion.value)})` : ""}`
645
679
  : Array.isArray(criterion.value)
646
- ? ` ${criterion.value.map((item) => (typeof item === "number" ? thresholdText(item) : item)).join(", ")}`
680
+ ? ` ${listText(criterion.value.map((item) => (typeof item === "number" ? thresholdText(item) : item)))}`
647
681
  : ` ${thresholdText(criterion.value)}`;
648
682
  return `${screenLabel(criterion.field)} ${symbols[criterion.op]}${value}`;
649
683
  }
@@ -698,7 +732,8 @@ export function screenDefinitionSyntax(): string {
698
732
  `${OBSERVED_SUBSET_FIELDS.join(" and ")} take only ${OBSERVED_SUBSET_OPERATORS.join(", ")};`,
699
733
  `${MEMBERSHIP_FIELDS.join(" and ")} take only ${MEMBERSHIP_OPERATORS.join(", ")}, eq with 1 for a member or 0;`,
700
734
  `the grades (${LETTER_GRADE_FIELDS.join(", ")}) are numbers from 1 (F) to 13 (A+), so B+ or better is gte 10, and gradeComposite runs from 1 to 5 (4.5 and up is Top);`,
701
- `category fields (${CATEGORY_FIELDS.join(", ")}) take in with an array of 1-25 names, present, missing.`,
735
+ `category fields (${CATEGORY_FIELDS.join(", ")}) take in with an array of 1-${MAX_CATEGORY_VALUES} names, present, missing;`,
736
+ `symbol takes up to ${MAX_SYMBOL_VALUES}, or one watchlist's name, which reads as its symbols.`,
702
737
  ].join(" ");
703
738
  }
704
739
 
@@ -714,8 +749,16 @@ export const EXAMPLE_SCREEN_DEFINITION: ScreenDefinition = {
714
749
  sort: { field: "marketCap", direction: "desc" },
715
750
  };
716
751
 
752
+ /** A screen of one watchlist's names: the name stands for its symbols. */
753
+ export const WATCHLIST_SCREEN_DEFINITION: ScreenDefinition = {
754
+ version: 1,
755
+ currency: "USD",
756
+ criteria: [{ field: "symbol", op: "in", value: ["Watchlist"] }],
757
+ sort: { field: "marketCap", direction: "desc" },
758
+ };
759
+
717
760
  const VALUE_SHAPES: Partial<Record<ScreenOperator, string>> = {
718
- in: "an array of 1-25 names, such as [\"Gold\"]",
761
+ in: `an array of 1-${MAX_CATEGORY_VALUES} names (symbol: 1-${MAX_SYMBOL_VALUES}, or a watchlist's name), such as ["Gold"]`,
719
762
  between: "[min, max] in ascending order, such as [5, 30]",
720
763
  };
721
764
 
@@ -747,7 +790,7 @@ function checkCriterion(criterion: unknown, index: number): ScreenCriterion {
747
790
  const value = item.value;
748
791
  const shape = VALUE_SHAPES[op] ?? "one number, such as 10000000000";
749
792
  const valid = op === "in"
750
- ? Array.isArray(value) && value.length >= 1 && value.length <= 25
793
+ ? Array.isArray(value) && value.length >= 1 && value.length <= maxCategoryValues(field)
751
794
  && value.every((entry) => typeof entry === "string" && entry.trim().length > 0 && entry.length <= 120)
752
795
  : op === "between"
753
796
  ? Array.isArray(value) && value.length === 2 && value.every((entry) => typeof entry === "number" && Number.isFinite(entry))
@@ -21,12 +21,14 @@ import {
21
21
  usePaneFooter,
22
22
  usePaneNoticeFooter,
23
23
  usePaneTabs,
24
+ useRowNotes,
24
25
  useTableLoadMore,
25
26
  type DataTableColumn,
26
27
  type DataTableVisibleRange,
27
28
  type SelectControl,
28
29
  } from "../../../components";
29
30
  import {
31
+ useAppSelector,
30
32
  useAsyncResource,
31
33
  useAutoRefresh,
32
34
  usePaneSettingValue,
@@ -42,6 +44,7 @@ import {
42
44
  LETTER_GRADE_FIELDS,
43
45
  NUMERIC_FIELDS,
44
46
  type NumericField,
47
+ type ScreenCriterion,
45
48
  type ScreenDefinition,
46
49
  type ScreenField,
47
50
  } from "../../../api-client/equity-screener";
@@ -74,6 +77,7 @@ import {
74
77
  formatScreenMetric,
75
78
  formatScreenValue,
76
79
  GRADE_DISPLAY_FIELDS,
80
+ MAX_SYMBOL_VALUES,
77
81
  gradeRankText,
78
82
  metricDate,
79
83
  parseScreenDefinition,
@@ -87,9 +91,11 @@ import {
87
91
  screenLabel,
88
92
  screenRowId,
89
93
  screenSignValue,
94
+ screenSymbols,
90
95
  screenYtdBase,
91
96
  splitGradeReason,
92
97
  } from "./model";
98
+ import { findNamedCollection, readWatchlistArgument } from "../../../portfolio/collection-name";
93
99
  import { useScreenResults } from "./results";
94
100
  import { screenWatchlistList } from "./watchlist";
95
101
  import { unmatchedCategoryText, unmatchedCategoryValues } from "./categories";
@@ -177,6 +183,8 @@ export function resultColumns(
177
183
  return fits(named) ? named : build(compact.slice(0, shown), exchange, sector, "compact");
178
184
  }
179
185
  const loadFields = () => fetchScreenFields();
186
+ const criterionRowId = (row: { id: string }) => row.id;
187
+ const criterionSignature = (row: { criterion: ScreenCriterion }) => JSON.stringify(row.criterion);
180
188
  const DETAIL_LABEL_WIDTH = 24;
181
189
  /** A long note under a value, wrapped to the detail's width rather than cut: one row per line, the label on the first. */
182
190
  function WrappedDetailRows({ label, text, width }: { label: string; text: string; width: number }) {
@@ -389,6 +397,26 @@ function EquityScreenView({
389
397
  [currentSaved?.name, data, definition, mode, openId, shownOrder], // eslint-disable-line react-hooks/exhaustive-deps
390
398
  );
391
399
  useMembersMenu("equity-screener:watchlist", watchlistList);
400
+ // A watchlist's name typed for the symbol field reads as its symbols, as `fn EQS` reads it.
401
+ const watchlists = useAppSelector((state) => state.config.watchlists);
402
+ const tickers = useAppSelector((state) => state.tickers);
403
+ const readWatchlist = useCallback((typed: string) => {
404
+ const watchlist = findNamedCollection(watchlists, typed);
405
+ if (!watchlist) return null;
406
+ const members = screenSymbols([...tickers.values()]
407
+ .filter((ticker) => ticker.metadata.watchlists.includes(watchlist.id))
408
+ .map((ticker) => ticker.metadata.ticker));
409
+ return members.length ? readWatchlistArgument(typed, watchlist, members, MAX_SYMBOL_VALUES) : null;
410
+ }, [tickers, watchlists]);
411
+ // How a saved criterion read a watchlist's name stays on its row until the criterion changes.
412
+ const criterionRows = useMemo(
413
+ () => definition.criteria.map((criterion, index) => ({ id: String(index), criterion })),
414
+ [definition.criteria],
415
+ );
416
+ const criterionNotes = useRowNotes<(typeof criterionRows)[number], string>(criterionRows, {
417
+ key: criterionRowId,
418
+ signature: criterionSignature,
419
+ });
392
420
  const selectedSaved =
393
421
  saved.data?.find((row) => row.id === savedSelectedId) ?? saved.data?.[0];
394
422
  useEffect(() => {
@@ -857,12 +885,14 @@ function EquityScreenView({
857
885
  value={editingCriterion ?? null}
858
886
  focused={focused}
859
887
  width={width}
888
+ readWatchlist={readWatchlist}
860
889
  onCancel={() => setEditing(null)}
861
- onSave={(criterion) => {
890
+ onSave={(criterion, note) => {
862
891
  const criteria = [...definition.criteria];
863
892
  if (editing < 0) criteria.push(criterion);
864
893
  else criteria[editing] = criterion;
865
894
  apply({ ...definition, criteria });
895
+ criterionNotes.setNote(String(editing < 0 ? criteria.length - 1 : editing), note);
866
896
  setEditing(null);
867
897
  }}
868
898
  />
@@ -908,10 +938,7 @@ function EquityScreenView({
908
938
  align: "left",
909
939
  },
910
940
  ]}
911
- items={definition.criteria.map((criterion, index) => ({
912
- id: String(index),
913
- criterion,
914
- }))}
941
+ items={criterionRows}
915
942
  focused={focused && editing === null && !saveForm}
916
943
  rootWidth={width}
917
944
  rootHeight={bodyHeight - 1}
@@ -923,7 +950,10 @@ function EquityScreenView({
923
950
  onChange: setSelectedCriterion,
924
951
  }}
925
952
  onActivate={(row) => setEditing(Number(row.id))}
926
- renderCell={(row) => ({ text: criterionText(row.criterion) })}
953
+ renderCell={(row) => {
954
+ const note = criterionNotes.noteFor(row);
955
+ return { text: criterionText(row.criterion), ...(note ? { note } : {}) };
956
+ }}
927
957
  sortColumnId={null}
928
958
  sortDirection="asc"
929
959
  emptyStateTitle="No criteria. All covered equities match."
@@ -2,13 +2,14 @@ import type { CloudExecutiveRowPayload } from "../../../api-client";
2
2
  import { formatShortDate } from "../../../utils/datetime-format";
3
3
  import { formatPercentRaw } from "../../../utils/format";
4
4
 
5
- /** "$36.3M", "$282K", "$50,000". */
6
- export function formatPay(value: number | null | undefined): string {
5
+ /** "$36.3M", "$282K", "$50,000"; a table column keeps the decimals (`fixedDecimals`), so $12.0M lines up under $36.3M. */
6
+ export function formatPay(value: number | null | undefined, { fixedDecimals = false }: { fixedDecimals?: boolean } = {}): string {
7
7
  if (value === null || value === undefined || !Number.isFinite(value))
8
8
  return "—";
9
9
  const abs = Math.abs(value);
10
- if (abs >= 1e9) return `$${(value / 1e9).toFixed(2).replace(/\.?0+$/, "")}B`;
11
- if (abs >= 1e6) return `$${(value / 1e6).toFixed(1).replace(/\.0$/, "")}M`;
10
+ const trim = (text: string, zeros: RegExp) => fixedDecimals ? text : text.replace(zeros, "");
11
+ if (abs >= 1e9) return `$${trim((value / 1e9).toFixed(2), /\.?0+$/)}B`;
12
+ if (abs >= 1e6) return `$${trim((value / 1e6).toFixed(1), /\.0$/)}M`;
12
13
  if (abs >= 1e5) return `$${Math.round(value / 1e3)}K`;
13
14
  return `$${Math.round(value).toLocaleString("en-US")}`;
14
15
  }
@@ -116,7 +116,7 @@ function renderOfficerCell(row: CloudExecutiveRowPayload, column: OfficerColumn)
116
116
  case "name": return { text: row.name, color: colors.textBright };
117
117
  case "title": return { text: row.title.replace(/\s+/g, " ").trim(), color: colors.textDim };
118
118
  case "equity": return { text: equityShare(row), color: colors.textDim };
119
- case "total": return { text: formatPay(row.total), color: colors.text, attributes: TextAttributes.BOLD };
119
+ case "total": return { text: formatPay(row.total, { fixedDecimals: true }), color: colors.text, attributes: TextAttributes.BOLD };
120
120
  }
121
121
  }
122
122