@gloom-sh/terminal 0.20.14 → 0.20.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api-client/data.ts +13 -3
- package/src/api-client/index.ts +54 -0
- package/src/api-client/install-experiments.ts +8 -7
- package/src/api-client/paths.ts +2 -1
- package/src/api-client/product-waitlist.ts +63 -0
- package/src/api-client/request.ts +4 -2
- package/src/api-client/types/billing.ts +45 -0
- package/src/api-client/types/econ.ts +3 -0
- package/src/api-client/yearly-plan.ts +132 -0
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/plugin-bindings.ts +3 -1
- package/src/app/pane-runtime/ticker-open-runtime.ts +6 -1
- package/src/app/since-last-visit/keys.ts +26 -0
- package/src/app/since-last-visit/model.ts +266 -0
- package/src/app/since-last-visit/strip.tsx +193 -0
- package/src/app/since-last-visit/use-since-last-visit.ts +289 -0
- package/src/app/since-last-visit/visit-tracker.ts +191 -0
- package/src/app.tsx +15 -0
- package/src/cli/commands/fred-series.ts +3 -1
- package/src/cli/commands/market.ts +8 -4
- package/src/cli/commands/overview.ts +65 -13
- package/src/cli/commands/system.ts +29 -1
- package/src/cli/commands/ticker.ts +12 -5
- package/src/cli/csv-export.ts +73 -0
- package/src/cli/desktop-pane-shot-api-policy.ts +4 -1
- package/src/cli/desktop-pane-shot-browser.ts +2 -1
- package/src/cli/desktop-pane-shot-view.ts +3 -7
- package/src/cli/desktop-pane-shot.ts +29 -30
- package/src/cli/help.ts +5 -2
- package/src/cli/history-rows.ts +24 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/options.ts +29 -1
- package/src/cli/pane-functions/catalog.ts +41 -4
- package/src/cli/pane-functions/function-help.ts +1 -1
- package/src/cli/pane-functions/headless.ts +70 -3
- package/src/cli/pane-functions/index.ts +4 -4
- package/src/cli/pane-functions/resolver.ts +43 -0
- package/src/cli/pane-functions/screenshot-bridge.ts +4 -2
- package/src/cli/pane-functions/screenshot-payload.ts +3 -0
- package/src/cli/report-tables.ts +37 -8
- package/src/cli/result.ts +3 -6
- package/src/cli/shot-temp-dir.ts +30 -0
- package/src/cli/suffixed-listing-rows.ts +11 -0
- package/src/components/chart/composite/composite-chart.tsx +3 -3
- package/src/components/chart/composite/legend.tsx +37 -7
- package/src/components/command-bar/commands/direct/index.ts +31 -8
- package/src/components/command-bar/commands/registry.ts +7 -0
- package/src/components/command-bar/routes/root/command-items.ts +8 -0
- package/src/components/command-bar/routes/root/results.ts +16 -0
- package/src/components/company-logo.tsx +10 -3
- package/src/components/data-table/sections.ts +6 -1
- package/src/components/layout/pane/title.ts +6 -2
- package/src/components/layout/shell/index.tsx +5 -1
- package/src/components/layout/shell/ticker-link-menu.ts +12 -9
- package/src/components/ticker/badge/format.ts +12 -3
- package/src/components/ticker/badge/index.tsx +9 -3
- package/src/components/ticker/list-table-view.tsx +119 -17
- package/src/components/ui/data-table/display-columns.ts +19 -0
- package/src/components/ui/data-table/hooks.ts +2 -3
- package/src/components/ui/data-table/index.tsx +43 -9
- package/src/components/ui/data-table/types.ts +21 -0
- package/src/components/ui/data-table/visible-range.ts +11 -1
- package/src/core/state/app/layout-reducer.ts +3 -1
- package/src/core/state/app/layout.ts +2 -2
- package/src/data/config/layout.ts +14 -0
- package/src/data/config/store/normalize.ts +11 -1
- package/src/i18n/es.ts +38 -0
- package/src/i18n/ja.ts +38 -0
- package/src/i18n/ko.ts +38 -0
- package/src/i18n/zh-cn.ts +38 -0
- package/src/i18n/zh-tw.ts +38 -0
- package/src/layout/pane-follow.ts +141 -4
- package/src/layout/pane-layout-move.ts +10 -7
- package/src/layout/ticker-navigation.ts +13 -19
- package/src/layout/ticker-retarget.ts +3 -2
- package/src/market-data/market/index-level.ts +19 -0
- package/src/plugins/builtin/account-management/keyboard.ts +14 -0
- package/src/plugins/builtin/account-management/model.ts +2 -0
- package/src/plugins/builtin/account-management/pane.tsx +79 -7
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +97 -0
- package/src/plugins/builtin/account-management/yearly-plan-row.tsx +359 -0
- package/src/plugins/builtin/awards/pane.tsx +12 -10
- package/src/plugins/builtin/changelog/index.tsx +6 -44
- package/src/plugins/builtin/changelog/versions.ts +17 -68
- package/src/plugins/builtin/chart-composer/pane.tsx +4 -1
- package/src/plugins/builtin/cloud/askg/executor.ts +2 -1
- package/src/plugins/builtin/cloud/askg/sources.ts +2 -1
- package/src/plugins/builtin/cpi/pane.tsx +1 -1
- package/src/plugins/builtin/credit-conditions/series.ts +2 -2
- package/src/plugins/builtin/debt-maturities/model.ts +1 -1
- package/src/plugins/builtin/earnings/board-model.ts +12 -0
- package/src/plugins/builtin/earnings/board-table.ts +8 -5
- package/src/plugins/builtin/earnings/board.tsx +38 -18
- package/src/plugins/builtin/earnings/highlight.ts +47 -0
- package/src/plugins/builtin/earnings/history-table.ts +1 -1
- package/src/plugins/builtin/earnings/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
- package/src/plugins/builtin/econ/calendar-model.ts +2 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +1 -256
- package/src/plugins/builtin/econ-statistics/cache.ts +1 -1
- package/src/plugins/builtin/econ-statistics/client.ts +11 -10
- package/src/plugins/builtin/econ-statistics/detail.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/headless.ts +42 -6
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
- package/src/plugins/builtin/econ-statistics/pane.tsx +7 -2
- package/src/plugins/builtin/econ-statistics/stats.ts +2 -1
- package/src/plugins/builtin/econ-statistics/view.ts +9 -3
- package/src/plugins/builtin/estimate-revisions/model.ts +1 -1
- package/src/plugins/builtin/exposure/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +6 -4
- package/src/plugins/builtin/market-valuation/detail.tsx +3 -3
- package/src/plugins/builtin/market-valuation/headless.ts +11 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +3 -1
- package/src/plugins/builtin/market-valuation/view.ts +14 -0
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +20 -8
- package/src/plugins/builtin/pe-band/pane.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/cli/render.ts +8 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +176 -17
- package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +90 -15
- package/src/plugins/builtin/portfolio-list/table.tsx +13 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +4 -2
- package/src/plugins/builtin/research/relative-valuation-headless.ts +15 -5
- package/src/plugins/builtin/research/relative-valuation-model.ts +7 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +7 -4
- package/src/plugins/builtin/shared/fred-catalog.ts +256 -0
- package/src/plugins/builtin/shared/headless-options.ts +1 -1
- package/src/plugins/builtin/shared/series-cache.ts +3 -0
- package/src/plugins/builtin/shared/series-detail-chart.tsx +3 -0
- package/src/plugins/builtin/short-interest/watch-pane.tsx +7 -7
- package/src/plugins/builtin/social-mentions/model.ts +2 -2
- package/src/plugins/builtin/thirteenf/pane.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +16 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +8 -4
- package/src/plugins/builtin/ticker-detail/financials/model.ts +51 -16
- package/src/plugins/builtin/ticker-detail/financials/nopat.ts +16 -0
- package/src/plugins/builtin/ticker-detail/financials/ratios.ts +44 -13
- package/src/plugins/builtin/ticker-detail/financials/schema.ts +33 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +4 -2
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +30 -4
- package/src/plugins/builtin/ticker-detail/headless.ts +254 -34
- package/src/plugins/builtin/ticker-detail/overview/model.ts +7 -3
- package/src/plugins/builtin/ticker-detail/pharma-signals/eligibility.ts +32 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/tab.tsx +162 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/waitlist.ts +126 -0
- package/src/plugins/builtin/ticker-detail/research-groups.ts +6 -4
- package/src/plugins/builtin/ticker-detail/research-tabs.ts +11 -0
- package/src/plugins/builtin/time-sales/headless.ts +4 -1
- package/src/plugins/builtin/time-sales/pane.tsx +2 -0
- package/src/plugins/builtin/time-sales/window.ts +12 -0
- package/src/plugins/builtin/treasury-auctions/client.ts +4 -0
- package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +2 -0
- package/src/plugins/builtin/treasury-daily/client.ts +23 -11
- package/src/portfolio/column-values.ts +20 -8
- package/src/portfolio/suffixed-listings.ts +3 -1
- package/src/portfolio/watchlist-groups.ts +212 -0
- package/src/react/ticker-source.ts +3 -1
- package/src/renderers/dom/styles.css +7 -0
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +2 -0
- package/src/sources/gloomberb-cloud/fred-publisher.ts +25 -0
- package/src/sources/gloomberb-cloud/fred-series.ts +1 -1
- package/src/state/app/bootstrap.ts +11 -0
- package/src/state/app/context/index.tsx +6 -0
- package/src/sync/collections-contributor.ts +5 -2
- package/src/sync/config-merge.ts +10 -2
- package/src/sync/sanitize.ts +28 -0
- package/src/telemetry/usage-counts.ts +17 -0
- package/src/time-series/base-series.ts +3 -0
- package/src/time-series/chart-seed.ts +1 -1
- package/src/time-series/financial-period-coverage.ts +4 -12
- package/src/time-series/ice-credit.ts +1 -0
- package/src/time-series/parsed-history-cache.ts +1 -1
- package/src/time-series/resolve.ts +1 -1
- package/src/time-series/types.ts +1 -0
- package/src/time-series/use-chart-resolution.ts +6 -1
- package/src/types/config.ts +32 -0
- package/src/types/headless.ts +9 -2
- package/src/types/plugin-context.ts +5 -0
- package/src/types/ticker.ts +14 -0
- package/src/ui/ascii-font.ts +1 -4
- package/src/utils/async-deadline.ts +2 -2
- package/src/utils/csv.ts +44 -5
- package/src/utils/futures-generic.ts +3 -0
- package/src/utils/throttled-fetch.ts +15 -1
package/src/cli/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { CLI_EXIT_CODES } from "./exit-codes";
|
|
|
28
28
|
import { asUsageError, fail, inferCliErrorOptions, printCliError } from "./errors";
|
|
29
29
|
import { cliStyles, setCliColorEnabledOverride, setCliPlainOverride, setCliWidthOverride } from "../utils/cli-output";
|
|
30
30
|
import { setDisplayTimeZone } from "../utils/utc-time";
|
|
31
|
+
import { setCsvDecimal } from "../utils/csv";
|
|
31
32
|
import { collectSavedCopies } from "../data/saved-copies";
|
|
32
33
|
import { search, searchCandidatesForCli, buildSearchReport } from "./commands/search";
|
|
33
34
|
import { ticker } from "./commands/ticker";
|
|
@@ -398,6 +399,8 @@ async function createRegistry(options: DispatchCliOptions = {}): Promise<CliComm
|
|
|
398
399
|
const config = await loadCliConfigIfAvailable();
|
|
399
400
|
// Every time a command prints follows the reader's zone from here on.
|
|
400
401
|
setDisplayTimeZone(config?.timezone);
|
|
402
|
+
// Every CSV is written with the reader's decimal mark from here on; --decimal decides for one run.
|
|
403
|
+
setCsvDecimal(config?.csvDecimal);
|
|
401
404
|
let registry: CliCommandRegistry | null = null;
|
|
402
405
|
const coreCommands = createCoreCliCommands(
|
|
403
406
|
() => listedCommands(registry!).map(({ command, source }) => ({ command, source })),
|
|
@@ -435,6 +438,7 @@ export async function dispatchCli(args: string[], options: DispatchCliOptions =
|
|
|
435
438
|
}
|
|
436
439
|
|
|
437
440
|
const registry = await createRegistry(options);
|
|
441
|
+
if (parsed.options.decimal) setCsvDecimal(parsed.options.decimal);
|
|
438
442
|
const token = normalizeCliCommandToken(foldTypedText(command));
|
|
439
443
|
let resolved = registry.lookup.get(token);
|
|
440
444
|
if (!resolved) {
|
package/src/cli/options.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CsvDecimal } from "../utils/csv";
|
|
1
2
|
export type CliOutputFormat = "text" | "json" | "csv" | "ndjson";
|
|
2
3
|
|
|
3
4
|
export interface CliGlobalOptions {
|
|
@@ -27,6 +28,12 @@ export interface CliGlobalOptions {
|
|
|
27
28
|
* `--output` read the flag themselves.
|
|
28
29
|
*/
|
|
29
30
|
output?: string;
|
|
31
|
+
/**
|
|
32
|
+
* `--decimal comma|dot`: the decimal mark of a `--csv` export, for this run.
|
|
33
|
+
* A decimal comma separates the cells with `;`. Unset, the `csvDecimal`
|
|
34
|
+
* setting decides, and without it the dot.
|
|
35
|
+
*/
|
|
36
|
+
decimal?: CsvDecimal;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
export interface ParsedCliArgs {
|
|
@@ -75,6 +82,14 @@ function parseColumnCount(value: string | undefined): number {
|
|
|
75
82
|
return parsed;
|
|
76
83
|
}
|
|
77
84
|
|
|
85
|
+
/** The decimal mark `--decimal` names: `comma` (or `,`), or `dot` (`.`, `point`). */
|
|
86
|
+
export function parseCsvDecimal(value: string | undefined, flag = "--decimal"): CsvDecimal {
|
|
87
|
+
const word = value?.trim().toLowerCase();
|
|
88
|
+
if (word === "comma" || word === ",") return "comma";
|
|
89
|
+
if (word === "dot" || word === "." || word === "point" || word === "period") return "dot";
|
|
90
|
+
throw new Error(`${flag} takes comma or dot: --csv --decimal comma writes 17,2 with cells split by ;, for a spreadsheet that reads a decimal comma.`);
|
|
91
|
+
}
|
|
92
|
+
|
|
78
93
|
function parseOutputFile(value: string | undefined): string {
|
|
79
94
|
if (!value?.trim() || value.startsWith("--")) throw new Error("--output needs a file to write, such as --csv --output report.csv.");
|
|
80
95
|
return value;
|
|
@@ -85,7 +100,7 @@ function commandWord(rawArgs: readonly string[]): string | undefined {
|
|
|
85
100
|
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
86
101
|
const arg = rawArgs[index]!;
|
|
87
102
|
if (arg === "--") return rawArgs[index + 1];
|
|
88
|
-
if (arg === "--limit" || arg === "--tail" || arg === "--width" || arg === "--output" || arg === "--out") index += 1;
|
|
103
|
+
if (arg === "--limit" || arg === "--tail" || arg === "--width" || arg === "--output" || arg === "--out" || arg === "--decimal") index += 1;
|
|
89
104
|
else if (!arg.startsWith("-")) return arg;
|
|
90
105
|
}
|
|
91
106
|
return undefined;
|
|
@@ -183,6 +198,15 @@ export function parseCliGlobalArgs(rawArgs: string[], settings: { ownsOutput?: b
|
|
|
183
198
|
options.output = parseOutputFile(arg.slice(arg.indexOf("=") + 1));
|
|
184
199
|
continue;
|
|
185
200
|
}
|
|
201
|
+
if (arg === "--decimal") {
|
|
202
|
+
index += 1;
|
|
203
|
+
options.decimal = parseCsvDecimal(rawArgs[index]);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (arg.startsWith("--decimal=")) {
|
|
207
|
+
options.decimal = parseCsvDecimal(arg.slice("--decimal=".length));
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
186
210
|
if (arg === "--limit" || arg === "--tail") {
|
|
187
211
|
index += 1;
|
|
188
212
|
options[arg === "--limit" ? "limit" : "tail"] = parseRowCount(arg, rawArgs[index]);
|
|
@@ -212,4 +236,8 @@ export function checkCliOutputFormat(parsed: Pick<ParsedCliArgs, "options" | "he
|
|
|
212
236
|
if (parsed.options.output !== undefined && parsed.options.format === "text" && !parsed.help) {
|
|
213
237
|
throw new Error("--output writes an export: add --csv, --json or --ndjson, such as --csv --output report.csv.");
|
|
214
238
|
}
|
|
239
|
+
// The text a terminal prints and JSON's numbers keep their dot: only a CSV is read by a spreadsheet's locale.
|
|
240
|
+
if (parsed.options.decimal !== undefined && parsed.options.format !== "csv" && !parsed.help) {
|
|
241
|
+
throw new Error("--decimal sets the decimal mark of a CSV export: add --csv, such as --csv --decimal comma.");
|
|
242
|
+
}
|
|
215
243
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
getPaneFunctionCapability,
|
|
15
15
|
MAX_INLINE_CHOICES,
|
|
16
16
|
optionChoices,
|
|
17
|
+
optionFlag,
|
|
17
18
|
optionFlags,
|
|
18
19
|
paneFunctionArgument,
|
|
19
20
|
type PaneFunctionCapability,
|
|
@@ -539,6 +540,9 @@ function scorePaneCatalogEntry(entry: PaneCatalogEntry, query: string): CatalogM
|
|
|
539
540
|
].filter((value): value is string => !!value).map((value) => normalizeLookupToken(value));
|
|
540
541
|
const flagKeys = entry.capability.options
|
|
541
542
|
.flatMap((option) => [option.key, ...(option.aliases ?? [])]).map((value) => normalizeLookupToken(value));
|
|
543
|
+
// A value one of its options takes names the function as a flag's own name does: `compounders` is EQS's preset.
|
|
544
|
+
const flagValues = new Set(entry.capability.options.flatMap((option) => (option.values ?? [])
|
|
545
|
+
.flatMap((value) => [value.value, ...(value.aliases ?? [])])).map((value) => normalizeLookupToken(value)));
|
|
542
546
|
const named = nameAndDescription(entry);
|
|
543
547
|
const flags = flagText(entry);
|
|
544
548
|
const wholeQuery = query.toLowerCase().trim().replace(/\s+/g, " ");
|
|
@@ -575,7 +579,7 @@ function scorePaneCatalogEntry(entry: PaneCatalogEntry, query: string): CatalogM
|
|
|
575
579
|
} else if (normalized !== term && named.includes(normalized)) {
|
|
576
580
|
score += 1;
|
|
577
581
|
matchedNamed += 1;
|
|
578
|
-
} else if (flagKeys.includes(normalized)) {
|
|
582
|
+
} else if (flagKeys.includes(normalized) || flagValues.has(normalized)) {
|
|
579
583
|
score += 2;
|
|
580
584
|
matchedFlagKeys += 1;
|
|
581
585
|
} else if (containsPhrase(flags, term)) {
|
|
@@ -587,6 +591,9 @@ function scorePaneCatalogEntry(entry: PaneCatalogEntry, query: string): CatalogM
|
|
|
587
591
|
}
|
|
588
592
|
|
|
589
593
|
if (matchedTerms === 0) return none;
|
|
594
|
+
// The whole query a value an option takes (GF's `operating margin` metric) is a name the function answers to.
|
|
595
|
+
const valueNamed = terms.length > 1 && flagValues.has(normalizeLookupToken(wholeQuery));
|
|
596
|
+
if (valueNamed) matchedNamed = terms.length;
|
|
590
597
|
// Words found only in a function's flags make a match when they are a flag's own name ("expiration") or,
|
|
591
598
|
// together, cover the whole query ("funding rate" in two flags); one stray word in a flag's description
|
|
592
599
|
// ("budget" in OSA's hedge budget) does not.
|
|
@@ -930,6 +937,30 @@ function renderCatalogEntry(entry: PaneCatalogEntry): string {
|
|
|
930
937
|
return lines.join("\n");
|
|
931
938
|
}
|
|
932
939
|
|
|
940
|
+
/**
|
|
941
|
+
* The command that runs a function with the option value a query names (`compounders` is EQS's `--preset
|
|
942
|
+
* compounders`), with the argument it needs first; null when the query is no value of its options.
|
|
943
|
+
*/
|
|
944
|
+
function optionValueCommand(entry: PaneCatalogEntry, query: string): string | null {
|
|
945
|
+
const wanted = normalizeLookupToken(query);
|
|
946
|
+
if (!wanted) return null;
|
|
947
|
+
// A word that opens one case of the function (FA's `roic`) runs it with that case's options.
|
|
948
|
+
const opening = entry.capability.opens?.find((candidate) => candidate.words.some((word) => normalizeLookupToken(word) === wanted));
|
|
949
|
+
if (opening?.options && Object.keys(opening.options).length > 0) {
|
|
950
|
+
const argument = opening.argument || argumentHint(entry);
|
|
951
|
+
const flags = Object.entries(opening.options).map(([key, value]) => `${optionFlag(key)} ${value}`).join(" ");
|
|
952
|
+
return `gloom fn ${entry.token}${argument ? ` ${argument}` : ""} ${flags}`;
|
|
953
|
+
}
|
|
954
|
+
for (const option of entry.capability.options) {
|
|
955
|
+
const value = option.values?.find((candidate) => [candidate.value, ...(candidate.aliases ?? [])]
|
|
956
|
+
.some((name) => normalizeLookupToken(name) === wanted));
|
|
957
|
+
if (!value) continue;
|
|
958
|
+
const argument = argumentHint(entry);
|
|
959
|
+
return `gloom fn ${entry.token}${argument ? ` ${argument}` : ""} ${optionFlag(option.key)} ${value.value}`;
|
|
960
|
+
}
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
|
|
933
964
|
/** The functions a search lists, one row each. */
|
|
934
965
|
function renderMatchesTable(shown: readonly PaneCatalogEntry[]): string {
|
|
935
966
|
return renderTable(
|
|
@@ -1025,9 +1056,12 @@ export function renderPaneCatalogReport(
|
|
|
1025
1056
|
const withGap = (text: string) => withSetting([gap ? wrapText(gap, width).join("\n") : "", text].filter(Boolean).join("\n\n"));
|
|
1026
1057
|
const withTerms = (text: string) => withGap([text, charted, terms].filter(Boolean).join("\n\n"));
|
|
1027
1058
|
if (args.query && entries.length === 1) {
|
|
1028
|
-
// A
|
|
1029
|
-
|
|
1030
|
-
|
|
1059
|
+
// A value of one of its options (EQS's `compounders` preset) is run with that option; a function found only
|
|
1060
|
+
// through a word of its description or keywords is the closest there is, and says so.
|
|
1061
|
+
const run = optionValueCommand(entries[0]!, args.query);
|
|
1062
|
+
const closest = run ? `${cliStyles.muted(`"${args.query.trim()}": ${run}`)}\n\n`
|
|
1063
|
+
: isClosestCatalogMatch(entries[0]!, args.query)
|
|
1064
|
+
? `${cliStyles.muted(`Closest match for "${args.query.trim()}": no function is named for it.`)}\n\n` : "";
|
|
1031
1065
|
return withTerms(`${closest}${renderCatalogEntry(entries[0]!)}`);
|
|
1032
1066
|
}
|
|
1033
1067
|
|
|
@@ -1049,10 +1083,13 @@ export function renderPaneCatalogReport(
|
|
|
1049
1083
|
const more = args.query
|
|
1050
1084
|
? `${hidden} more ${hidden === 1 ? "match" : "matches"}: refine the query, or add --all to list every match.`
|
|
1051
1085
|
: `Add --all to list all ${entries.length}.`;
|
|
1086
|
+
// The functions that take the query as an option's value, with the command that runs them on it.
|
|
1087
|
+
const runs = args.query ? shown.flatMap((entry) => optionValueCommand(entry, args.query) ?? []).slice(0, 3) : [];
|
|
1052
1088
|
const lines = [
|
|
1053
1089
|
`${renderSection(title)} ${cliStyles.muted(`(${count})`)}`,
|
|
1054
1090
|
renderMatchesTable(shown),
|
|
1055
1091
|
"",
|
|
1092
|
+
...runs.length > 0 ? [note(`"${args.query.trim()}": ${runs.join("; ")}`)] : [],
|
|
1056
1093
|
note([
|
|
1057
1094
|
loose ? "No function carries every word of the query; these are the closest." : "",
|
|
1058
1095
|
"gloom catalog <function> shows its options and examples.",
|
|
@@ -411,7 +411,7 @@ export const FUNCTION_HELP: Readonly<Record<string, FunctionHelp>> = {
|
|
|
411
411
|
bloomberg: ["CACS"],
|
|
412
412
|
},
|
|
413
413
|
EVTS: {
|
|
414
|
-
summary: "The market board: report days with implied and past moves,
|
|
414
|
+
summary: "The market board: report days with implied and past moves. In the pane, a ticker opens its next report day, or its latest past one, with its row selected. An explicit week or day keeps that range.",
|
|
415
415
|
usage: ["EVTS", "EVTS NVDA", "gloom fn EVTS --week last", "gloom fn EVTS --date 2026-10-15"],
|
|
416
416
|
keys: [key("t", "icker"), key("e", "stimates"), key("c", "alls"), key("a", "nalysts")],
|
|
417
417
|
data: EARNINGS_DAYS,
|
|
@@ -55,6 +55,7 @@ import { noArgumentMessage } from "./capabilities";
|
|
|
55
55
|
import { lockedHeadlessReport } from "./lock-note";
|
|
56
56
|
import { resumeStateKey } from "../../plugins/registry/plugin-state";
|
|
57
57
|
import { logFailure } from "../../utils/log-failure";
|
|
58
|
+
import { windowRows, type RowWindow, type RowWindowOptions } from "../row-window";
|
|
58
59
|
|
|
59
60
|
interface SerializableHeadlessColumn {
|
|
60
61
|
key: string;
|
|
@@ -539,7 +540,11 @@ function seriesValue(series: HeadlessSeries, value: number | null): string {
|
|
|
539
540
|
if (unit === "%" || unit === "pp") return value.toFixed(2);
|
|
540
541
|
if (unit === "x" || unit === "ratio") return value !== 0 && Math.abs(value) < 0.1 ? value.toPrecision(3) : value.toFixed(2);
|
|
541
542
|
if (unit === "score") return value.toFixed(1);
|
|
542
|
-
|
|
543
|
+
// A count or amount of five digits or more groups its thousands as every other table does (27,256,037 shares).
|
|
544
|
+
const plain = displayNumber(value);
|
|
545
|
+
const [whole, fraction] = plain.split(".");
|
|
546
|
+
return Math.abs(value) >= 10_000 && /^-?\d+(?:\.\d+)?$/.test(plain)
|
|
547
|
+
? `${whole!.replace(/\B(?=(\d{3})+$)/g, ",")}${fraction ? `.${fraction}` : ""}` : plain;
|
|
543
548
|
}
|
|
544
549
|
|
|
545
550
|
function renderRows(
|
|
@@ -886,6 +891,9 @@ export function headlessReportTables(
|
|
|
886
891
|
// A section of one name or one date says so for every line it exports.
|
|
887
892
|
const named = {
|
|
888
893
|
...(section.symbol?.trim() ? { symbolOrSeries: section.symbol.trim() } : {}),
|
|
894
|
+
...(section.unit?.trim() ? { currencyOrUnit: section.unit.trim() } : {}),
|
|
895
|
+
...(section.interval?.trim() ? { interval: section.interval.trim() } : {}),
|
|
896
|
+
...("source" in section && section.source?.trim() ? { source: section.source.trim() } : {}),
|
|
889
897
|
...(section.asOf === null ? { asOf: null } : section.asOf?.trim() ? { asOf: section.asOf.trim() } : {}),
|
|
890
898
|
...(section.period?.trim() ? { period: section.period.trim() } : {}),
|
|
891
899
|
...(section.released?.trim() ? { released: section.released.trim() } : {}),
|
|
@@ -908,14 +916,16 @@ export function headlessReportTables(
|
|
|
908
916
|
const rowIdentities = section.entries.some((entry) => own(entry)) ? section.entries.map(own) : undefined;
|
|
909
917
|
return { ...entries, ...(Object.keys(named).length > 0 ? { identity: named } : {}), ...(rowIdentities ? { rowIdentities } : {}) };
|
|
910
918
|
}
|
|
911
|
-
const table = exportRowsTable(section.title, displayedColumns(columnsFor(section.rows, section.columns, definition.columns)), section.rows,
|
|
919
|
+
const table = exportRowsTable(section.title, displayedColumns(columnsFor(section.rows, section.columns, definition.columns)), section.rows,
|
|
920
|
+
{ status: true, appendedColumns: section.appendedColumns });
|
|
912
921
|
const identity = {
|
|
913
922
|
...named,
|
|
914
923
|
...(section.unit?.trim() ? { currencyOrUnit: section.unit.trim() } : {}),
|
|
915
924
|
...(section.interval?.trim() ? { interval: section.interval.trim() } : {}),
|
|
916
925
|
};
|
|
917
926
|
const rowIdentities = rowIdentitiesOf(section.rows, section);
|
|
918
|
-
return { ...table, ...(
|
|
927
|
+
return { ...table, ...(section.appendedColumns ? { appendedColumns: section.appendedColumns } : {}),
|
|
928
|
+
...(Object.keys(identity).length > 0 ? { identity } : {}), ...(rowIdentities ? { rowIdentities } : {}) };
|
|
919
929
|
});
|
|
920
930
|
break;
|
|
921
931
|
case "series": {
|
|
@@ -1100,6 +1110,62 @@ function withUnreached(
|
|
|
1100
1110
|
return nothingServed && unreached ? { ...freshness, unreached: true } : freshness;
|
|
1101
1111
|
}
|
|
1102
1112
|
|
|
1113
|
+
/** What a cut says: which rows of how many it kept, and of which table when the report has several. */
|
|
1114
|
+
function cutNote(window: RowWindowOptions, cut: RowWindow<unknown>, table?: string): string | null {
|
|
1115
|
+
if (cut.rows.length >= cut.total) return null;
|
|
1116
|
+
const kept = `${window.tail != null ? (cut.kept === "newest" ? "newest" : "last") : "first"} ${cut.rows.length} of ${cut.total} rows`;
|
|
1117
|
+
return `${table ? `${table}: ` : ""}${cut.note ?? `${kept} (--${window.tail != null ? "tail" : "limit"} ${window.tail ?? window.limit})`}`;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* The report's rows as `--limit` and `--tail` keep them, for a function with no option of its own for them
|
|
1122
|
+
* (`fn CTM CL --limit 3`): the first or last n of each table, of a series' points the oldest or newest n, as every
|
|
1123
|
+
* command that prints a list keeps them; the notes say what was cut.
|
|
1124
|
+
*/
|
|
1125
|
+
function windowHeadlessResult(shape: HeadlessPaneDefinition["shape"], result: HeadlessPaneResult, window: RowWindowOptions): HeadlessPaneResult {
|
|
1126
|
+
const notes: string[] = [];
|
|
1127
|
+
const cut = <Row,>(rows: readonly Row[], table?: string, dateOf?: (row: Row) => unknown): Row[] => {
|
|
1128
|
+
const kept = windowRows(rows, window, dateOf);
|
|
1129
|
+
const note = cutNote(window, kept, table);
|
|
1130
|
+
if (note) notes.push(note);
|
|
1131
|
+
return kept.rows;
|
|
1132
|
+
};
|
|
1133
|
+
const quiet = <Row,>(rows: readonly Row[] | undefined) => rows ? windowRows(rows, window).rows : undefined;
|
|
1134
|
+
let windowed: HeadlessPaneResult;
|
|
1135
|
+
switch (shape) {
|
|
1136
|
+
case "rows": {
|
|
1137
|
+
const rows = result as HeadlessRowsResult;
|
|
1138
|
+
windowed = { ...rows, rows: cut(rows.rows), ...(rows.textRows ? { textRows: quiet(rows.textRows)! } : {}) };
|
|
1139
|
+
break;
|
|
1140
|
+
}
|
|
1141
|
+
case "bundle": {
|
|
1142
|
+
const bundle = result as HeadlessBundleResult;
|
|
1143
|
+
const several = bundle.sections.filter((section) => section.rows).length > 1;
|
|
1144
|
+
windowed = { ...bundle, sections: bundle.sections.map((section) => !section.rows ? section : {
|
|
1145
|
+
...section, rows: cut(section.rows, several ? section.title : undefined), ...(section.textRows ? { textRows: quiet(section.textRows)! } : {}),
|
|
1146
|
+
}) };
|
|
1147
|
+
break;
|
|
1148
|
+
}
|
|
1149
|
+
case "series": {
|
|
1150
|
+
const series = result as HeadlessSeriesResult;
|
|
1151
|
+
windowed = { ...series, series: series.series.map((entry) => ({
|
|
1152
|
+
...entry, points: cut(entry.points, series.series.length > 1 ? entry.label : undefined, (point) => point.date),
|
|
1153
|
+
})) };
|
|
1154
|
+
break;
|
|
1155
|
+
}
|
|
1156
|
+
case "snapshot": {
|
|
1157
|
+
const snapshot = result as HeadlessSnapshotResult;
|
|
1158
|
+
windowed = { ...snapshot, items: cut(snapshot.items) };
|
|
1159
|
+
break;
|
|
1160
|
+
}
|
|
1161
|
+
default: {
|
|
1162
|
+
const _exhaustive: never = shape;
|
|
1163
|
+
return _exhaustive;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
return notes.length > 0 ? { ...windowed, notes: [...windowed.notes ?? [], ...notes] } : windowed;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1103
1169
|
export async function buildHeadlessFunctionReport(
|
|
1104
1170
|
resolved: ResolvedPaneFunction,
|
|
1105
1171
|
context: MarketContext,
|
|
@@ -1108,6 +1174,7 @@ export async function buildHeadlessFunctionReport(
|
|
|
1108
1174
|
let loaded: LoadedHeadlessPaneModel;
|
|
1109
1175
|
try {
|
|
1110
1176
|
loaded = await loadResolvedHeadlessPaneModel(resolved, context, rawArgument);
|
|
1177
|
+
if (resolved.rowWindow) loaded = { ...loaded, result: windowHeadlessResult(loaded.definition.shape, loaded.result, resolved.rowWindow) };
|
|
1111
1178
|
} catch (error) {
|
|
1112
1179
|
// A Pro pane the server refused reports what its wall covers, as its rendered view does.
|
|
1113
1180
|
const locked = await lockedHeadlessReport(resolved, error, () => (
|
|
@@ -50,6 +50,7 @@ import { DATA_SERVICE_UNREACHABLE_MESSAGE, isNetworkFailure } from "../../utils/
|
|
|
50
50
|
import { isTickerLinkPeer } from "../../layout/ticker-navigation";
|
|
51
51
|
import { knownGapMessage, commandPointer, commandPointerLeads, topicPointer } from "../known-gaps";
|
|
52
52
|
import { selectReportTables, splitCsvFooter, withRefusedRows, type CliReportTables } from "../report-tables";
|
|
53
|
+
import { portableCsv } from "../csv-export";
|
|
53
54
|
import { cliOutputWritten, printCliResult, serializeCliResult, type CliErrorObject } from "../result";
|
|
54
55
|
import { checkOutputPath, resolveOutputPath, writeOutputFile } from "../output-file";
|
|
55
56
|
import type { CatalogCommandHit } from "../unknown-command";
|
|
@@ -75,7 +76,7 @@ async function withPaneRuntime<T>(
|
|
|
75
76
|
registry: PaneFunctionCatalog;
|
|
76
77
|
resolved: ResolvedPaneFunction;
|
|
77
78
|
}) => Promise<T>,
|
|
78
|
-
settings: { strictHeadlessOptions?: boolean; tableSection?: boolean; command?: "fn" | "shot" } = {},
|
|
79
|
+
settings: { strictHeadlessOptions?: boolean; tableSection?: boolean; rowWindow?: boolean; command?: "fn" | "shot" } = {},
|
|
79
80
|
): Promise<T> {
|
|
80
81
|
return withMarketData(ctx, async (market) => {
|
|
81
82
|
const context: MarketContext = ctx.cliOptions.refresh ? { ...market, refresh: true } : market;
|
|
@@ -471,10 +472,9 @@ export async function runPaneFunction(args: string[], ctx: CliCommandContext) {
|
|
|
471
472
|
// A report with no data writes no file: a header alone would read as a screen that matched nothing. It fails
|
|
472
473
|
// as plain --json fails, with its code and whether to retry.
|
|
473
474
|
if (failure) failWithError({ ...failure, details: `Nothing was written to ${outputPath}.` });
|
|
474
|
-
// A CSV file holds its rows alone; its closing source and note lines go to stderr, as printed CSV's do.
|
|
475
475
|
const written = renderForFile(() => serializeCliResult(result, ctx.cliOptions, render));
|
|
476
476
|
const { csv, footer } = ctx.cliOptions.format === "csv" ? splitCsvFooter(written) : { csv: written, footer: [] };
|
|
477
|
-
await writeOutputFile(outputPath, `${csv}\n`);
|
|
477
|
+
await writeOutputFile(outputPath, `${ctx.cliOptions.format === "csv" ? portableCsv(written, warnings) : csv}\n`);
|
|
478
478
|
if (!ctx.cliOptions.quiet) for (const line of footer) console.error(line);
|
|
479
479
|
// What was written and where; warnings go to stderr as they would beside printed rows, and JSON keeps its envelope.
|
|
480
480
|
const saved = { output: outputPath, format: ctx.cliOptions.format, rows: report.data.rowCount, replaced: replacing };
|
|
@@ -485,7 +485,7 @@ export async function runPaneFunction(args: string[], ctx: CliCommandContext) {
|
|
|
485
485
|
}
|
|
486
486
|
ctx.printResult(result, render);
|
|
487
487
|
if (failure) process.exitCode = CLI_EXIT_CODES.error;
|
|
488
|
-
}, { strictHeadlessOptions: true, tableSection: true });
|
|
488
|
+
}, { strictHeadlessOptions: true, tableSection: true, rowWindow: true });
|
|
489
489
|
});
|
|
490
490
|
}
|
|
491
491
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RowWindowOptions } from "../row-window";
|
|
1
2
|
import { logFailure } from "../../utils/log-failure";
|
|
2
3
|
import type { PaneInstanceConfig } from "../../types/config";
|
|
3
4
|
import { CHART_COMPOSER_PANE_ID } from "../../types/config";
|
|
@@ -79,6 +80,11 @@ export interface ResolvedPaneFunction {
|
|
|
79
80
|
optionSettings: Record<string, unknown>;
|
|
80
81
|
capability: PaneFunctionCapability;
|
|
81
82
|
options: NormalizedPaneFunctionOptions;
|
|
83
|
+
/**
|
|
84
|
+
* `--limit` and `--tail` of a report whose function takes no such option of its own: the rows the report keeps,
|
|
85
|
+
* as every command that prints a list keeps them (row-window).
|
|
86
|
+
*/
|
|
87
|
+
rowWindow?: RowWindowOptions;
|
|
82
88
|
/** `--section` of a report: the table `--csv` and `--ndjson` write, when the function has no `section` option of its own. */
|
|
83
89
|
tableSection?: string | true;
|
|
84
90
|
}
|
|
@@ -510,6 +516,8 @@ export async function resolvePaneFunction(
|
|
|
510
516
|
resolutionSettings: {
|
|
511
517
|
strictHeadlessOptions?: boolean;
|
|
512
518
|
tableSection?: boolean;
|
|
519
|
+
/** `fn`: a `--limit` or `--tail` the function takes no option for picks the report's rows (`rowWindow`). */
|
|
520
|
+
rowWindow?: boolean;
|
|
513
521
|
command?: "fn" | "shot";
|
|
514
522
|
/** The plugins whose catalog series a name that opens nothing is pointed at. */
|
|
515
523
|
seriesSources?: readonly SeriesSource[];
|
|
@@ -533,6 +541,14 @@ export async function resolvePaneFunction(
|
|
|
533
541
|
throw new Error(`Template "${template?.id}" points at missing pane "${template?.paneId}".`);
|
|
534
542
|
}
|
|
535
543
|
const headless = getHeadlessPaneDefinition(template, pane);
|
|
544
|
+
// A report that reads a list for a pane that shows one ticker (FA, INS): a capture of the list is refused with
|
|
545
|
+
// both commands, rather than read as one ticker named by the whole list.
|
|
546
|
+
const asked = argumentSymbols(args.arg ?? "");
|
|
547
|
+
if (resolutionSettings.command === "shot" && headless?.argument.kind === "tickers" && template?.shortcut?.argKind === "ticker"
|
|
548
|
+
&& !template.opensTickerList && asked.length > 1) {
|
|
549
|
+
const code = paneFunctionCode(template, pane, registry);
|
|
550
|
+
throw new Error(`${code}'s pane shows one ticker: gloom shot ${code} ${asked[0]}. Its report reads all ${asked.length} in one table: gloom fn ${code} ${asked.join(" ")}`);
|
|
551
|
+
}
|
|
536
552
|
const createOptions = withTickerList(template, buildCreateOptions(template, args.arg), headless, args.arg, paneFunctionCode(template, pane, registry));
|
|
537
553
|
const capability = getPaneFunctionCapability(template, pane);
|
|
538
554
|
let tableSection: string | true | undefined;
|
|
@@ -554,6 +570,9 @@ export async function resolvePaneFunction(
|
|
|
554
570
|
if (bank) throw new UnknownPaneFunctionError(args.target, bank.details, null, bank.message);
|
|
555
571
|
throw new Error(noArgumentMessage(capability.options, token, args.arg, resolutionSettings.command ?? "fn"));
|
|
556
572
|
}
|
|
573
|
+
// `--limit` and `--tail` are global options: a report whose function has none of its own keeps the rows they say.
|
|
574
|
+
const rowWindow = resolutionSettings.rowWindow ? reportRowWindow(capability, args.options) : null;
|
|
575
|
+
if (rowWindow) args = { ...args, options: rowWindow.options };
|
|
557
576
|
const normalizedOptions = normalizeCapabilityOptions(capability, args.options, {
|
|
558
577
|
strict: args.requireBotSafe || capability.strictOptions === true || (!!headless && resolutionSettings.strictHeadlessOptions === true),
|
|
559
578
|
code: token,
|
|
@@ -580,12 +599,36 @@ export async function resolvePaneFunction(
|
|
|
580
599
|
optionSettings: settings,
|
|
581
600
|
capability,
|
|
582
601
|
options: normalizedOptions,
|
|
602
|
+
...(rowWindow ? { rowWindow: rowWindow.window } : {}),
|
|
583
603
|
...(tableSection !== undefined ? { tableSection } : {}),
|
|
584
604
|
};
|
|
585
605
|
resolved.instance = await buildPaneInstance(resolved, context, args.arg, resolutionSettings.command ?? "fn");
|
|
586
606
|
return resolved;
|
|
587
607
|
}
|
|
588
608
|
|
|
609
|
+
/**
|
|
610
|
+
* The `--limit` and `--tail` a function with no option of that name leaves to the report, taken out of its options;
|
|
611
|
+
* null when neither was given or the function reads both itself. A function with options of its own for them
|
|
612
|
+
* (DVD's `--limit`) checks and reads them there.
|
|
613
|
+
*/
|
|
614
|
+
function reportRowWindow(
|
|
615
|
+
capability: PaneFunctionCapability,
|
|
616
|
+
options: Record<string, string | true>,
|
|
617
|
+
): { window: RowWindowOptions; options: Record<string, string | true> } | null {
|
|
618
|
+
const window: RowWindowOptions = {};
|
|
619
|
+
const rest = { ...options };
|
|
620
|
+
for (const key of ["limit", "tail"] as const) {
|
|
621
|
+
const value = options[key];
|
|
622
|
+
if (value === undefined || capabilityHasOption(capability, key)) continue;
|
|
623
|
+
const count = Number(value);
|
|
624
|
+
if (value === true || !Number.isInteger(count) || count < 1) throw new Error(`--${key} must be a positive integer.`);
|
|
625
|
+
window[key] = count;
|
|
626
|
+
delete rest[key];
|
|
627
|
+
}
|
|
628
|
+
if (window.limit != null && window.tail != null) throw new Error("--limit and --tail each pick rows; give one of them.");
|
|
629
|
+
return window.limit != null || window.tail != null ? { window, options: rest } : null;
|
|
630
|
+
}
|
|
631
|
+
|
|
589
632
|
/**
|
|
590
633
|
* A one-ticker template whose pane also opens on a list (`opensTickerList`:
|
|
591
634
|
* DVD's ranking): the list is passed as `symbols`, so `shot` draws the same
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type HttpProxyRequestEnvelope,
|
|
9
9
|
type HttpProxyResponseEnvelope,
|
|
10
10
|
} from "../../utils/http-proxy-response";
|
|
11
|
+
import { signalWithTimeout } from "../../utils/async-deadline";
|
|
11
12
|
import { fetchCheckingRedirects, readBytesWithin } from "../../utils/http-proxy-upstream";
|
|
12
13
|
import { isPublicAddress } from "../../utils/public-address";
|
|
13
14
|
import type { DesktopPaneShotApiProxy, DesktopPaneShotBridge } from "../desktop-pane-shot";
|
|
@@ -146,7 +147,7 @@ export function createDesktopShotBridge(
|
|
|
146
147
|
args,
|
|
147
148
|
);
|
|
148
149
|
},
|
|
149
|
-
httpFetch: (request) => runDesktopShotHttpFetch(request, httpOptions),
|
|
150
|
+
httpFetch: (request, signal) => runDesktopShotHttpFetch(request, httpOptions, signal),
|
|
150
151
|
};
|
|
151
152
|
}
|
|
152
153
|
|
|
@@ -196,6 +197,7 @@ async function checkShotHttpTarget(
|
|
|
196
197
|
async function runDesktopShotHttpFetch(
|
|
197
198
|
request: HttpProxyRequestEnvelope,
|
|
198
199
|
options: ShotHttpOptions,
|
|
200
|
+
signal?: AbortSignal,
|
|
199
201
|
): Promise<HttpProxyResponseEnvelope> {
|
|
200
202
|
const resolve = options.resolveHost ?? resolveHost;
|
|
201
203
|
const addresses = new Map<string, string>();
|
|
@@ -218,7 +220,7 @@ async function runDesktopShotHttpFetch(
|
|
|
218
220
|
return fetchShotHttpAddress(url, init ?? {}, address);
|
|
219
221
|
}) as typeof fetch,
|
|
220
222
|
check: checkTarget,
|
|
221
|
-
signal:
|
|
223
|
+
signal: signalWithTimeout(signal, SHOT_BRIDGE_HTTP_TIMEOUT_MS),
|
|
222
224
|
});
|
|
223
225
|
if ("error" in result) throw new Error(result.error);
|
|
224
226
|
const { response } = result;
|
|
@@ -201,6 +201,9 @@ export async function buildDesktopShotPayload(
|
|
|
201
201
|
if (isFinancialAnalysisFunction(resolved) && !initialPaneState.activeTabId) {
|
|
202
202
|
initialPaneState.activeTabId = "financials";
|
|
203
203
|
}
|
|
204
|
+
// A capture of a ratio tab shows each ratio's inputs (NOPAT, invested capital), as the report lists them; the
|
|
205
|
+
// pane opens them collapsed for a reader who opens the one they want.
|
|
206
|
+
if (shotRatioTab(resolved)) initialPaneState.financialRatiosExpanded = true;
|
|
204
207
|
// The pane opens on what the report found (13F: the fund a name resolved to, on its view's tab).
|
|
205
208
|
const opened = resolved.headless?.shotState
|
|
206
209
|
? await resolved.headless.shotState(
|
package/src/cli/report-tables.ts
CHANGED
|
@@ -82,6 +82,11 @@ export interface CliReportColumn<Row = Record<string, unknown>> {
|
|
|
82
82
|
unitColumn?: boolean;
|
|
83
83
|
/** CSV and NDJSON write the figure to the digits `format` draws (figureAsDrawn); JSON keeps it whole. */
|
|
84
84
|
exportAsShown?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* A column the export gained after its others were set (RV's `Fwd P/E period`): it closes the row, after the
|
|
87
|
+
* fixed columns and `retrieved_at` (`appendedColumns`), so no column an earlier export had moves.
|
|
88
|
+
*/
|
|
89
|
+
exportLast?: boolean;
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
/** A label/value line of a report. `unit` names the unit of a numeric `value` when `formatted` cannot say it. */
|
|
@@ -111,6 +116,8 @@ interface ResolvedColumn {
|
|
|
111
116
|
unit?: string;
|
|
112
117
|
/** The unit always has a column of its own (`unitColumn`). */
|
|
113
118
|
unitColumn?: boolean;
|
|
119
|
+
/** The column closes the row after the fixed columns (`exportLast`). */
|
|
120
|
+
last?: boolean;
|
|
114
121
|
}
|
|
115
122
|
|
|
116
123
|
const BLANK = { kind: "blank" } as const;
|
|
@@ -397,7 +404,8 @@ function assembleTable(title: string, columns: readonly ResolvedColumn[], rowCou
|
|
|
397
404
|
const units = columns.map((column) => rowCount === 0 && column.unit != null ? new Set([column.unit]) : numberUnits(column.cells));
|
|
398
405
|
const mixed = units.map((columnUnits, index) => columnUnits.size > 1 || columns[index]!.unitColumn === true);
|
|
399
406
|
const byRow = mixed.some(Boolean) ? rowUnits(columns, mixed, rowCount) : null;
|
|
400
|
-
|
|
407
|
+
type LayoutColumn = { header: string; value: (row: number) => CliReportValue };
|
|
408
|
+
const columnLayout = (column: ResolvedColumn, index: number): LayoutColumn[] => {
|
|
401
409
|
const columnUnits = units[index]!;
|
|
402
410
|
const cell = (row: number) => cellValue(column.cells[row] ?? BLANK);
|
|
403
411
|
if (index === 0 && byRow) {
|
|
@@ -418,12 +426,18 @@ function assembleTable(title: string, columns: readonly ResolvedColumn[], rowCou
|
|
|
418
426
|
},
|
|
419
427
|
},
|
|
420
428
|
];
|
|
421
|
-
}
|
|
429
|
+
};
|
|
430
|
+
const layoutOf = new Map<ResolvedColumn, LayoutColumn[]>(columns.map((column, index) => [column, columnLayout(column, index)]));
|
|
431
|
+
const layout = columns.flatMap((column) => layoutOf.get(column)!);
|
|
422
432
|
if (status) layout.push({ header: status.header, value: (row: number) => status.values[row] ?? "" });
|
|
433
|
+
// A column the export gained later (`exportLast`) closes the row, after the status and the fixed columns.
|
|
434
|
+
const appended = columns.flatMap((column) => column.last ? layoutOf.get(column) ?? [] : []);
|
|
435
|
+
const ordered = [...layout.filter((entry) => !appended.includes(entry)), ...appended];
|
|
423
436
|
return {
|
|
424
437
|
title,
|
|
425
|
-
columns:
|
|
426
|
-
rows: Array.from({ length: rowCount }, (_, row) =>
|
|
438
|
+
columns: ordered.map((column) => column.header),
|
|
439
|
+
rows: Array.from({ length: rowCount }, (_, row) => ordered.map((column) => column.value(row))),
|
|
440
|
+
...appended.length > 0 ? { appendedColumns: appended.length } : {},
|
|
427
441
|
};
|
|
428
442
|
}
|
|
429
443
|
|
|
@@ -525,7 +539,7 @@ export function exportRowsTable<Row extends Record<string, unknown>>(
|
|
|
525
539
|
title: string,
|
|
526
540
|
columns: readonly CliReportColumn<Row>[],
|
|
527
541
|
rows: readonly Row[],
|
|
528
|
-
{ status = false, rowUnitKey }: { status?: boolean; rowUnitKey?: string } = {},
|
|
542
|
+
{ status = false, rowUnitKey, appendedColumns = 0 }: { status?: boolean; rowUnitKey?: string; appendedColumns?: number } = {},
|
|
529
543
|
): CliReportTable {
|
|
530
544
|
const reasons = rows.map((): Array<{ header: string; text: string }> => []);
|
|
531
545
|
const units = columns.map(columnUnit);
|
|
@@ -566,13 +580,21 @@ export function exportRowsTable<Row extends Record<string, unknown>>(
|
|
|
566
580
|
};
|
|
567
581
|
const unit = units[columnIndex];
|
|
568
582
|
const withUnit = unit == null ? table : { ...table, unit };
|
|
569
|
-
|
|
583
|
+
const last = column.exportLast ? { ...withUnit, last: true } : withUnit;
|
|
584
|
+
return column.unitColumn && column.unitKey && !inRowUnit ? { ...last, unitColumn: true } : last;
|
|
570
585
|
});
|
|
571
586
|
const statusColumn = withStatus ? {
|
|
572
587
|
header: columns.some((column) => column.header.trim().toLowerCase() === "status") ? "value_status" : "status",
|
|
573
588
|
values: reasons.map(statusText),
|
|
574
589
|
} : undefined;
|
|
575
|
-
|
|
590
|
+
const table = assembleTable(title, resolved, rows.length, statusColumn);
|
|
591
|
+
if (appendedColumns && statusColumn) {
|
|
592
|
+
const before = table.columns.length - 1 - appendedColumns;
|
|
593
|
+
const reorder = <Value,>(values: Value[]) => [...values.slice(0, before), values.at(-1)!, ...values.slice(before, -1)];
|
|
594
|
+
table.columns = reorder(table.columns);
|
|
595
|
+
table.rows = table.rows.map(reorder);
|
|
596
|
+
}
|
|
597
|
+
return appendedColumns ? { ...table, appendedColumns } : table;
|
|
576
598
|
}
|
|
577
599
|
|
|
578
600
|
/** Label/value lines as `Metric,Value`; a number's unit moves into its label. */
|
|
@@ -772,7 +794,14 @@ export function splitCsvFooter(text: string): { csv: string; footer: string[] }
|
|
|
772
794
|
const last = blocks.at(-1) ?? "";
|
|
773
795
|
const lines = last.split("\n");
|
|
774
796
|
if (!last || !lines.every(isComment) || lines.some((line) => line.startsWith("# section: "))) return { csv: text, footer: [] };
|
|
775
|
-
|
|
797
|
+
const csv = blocks.slice(0, -1).join("\n\n");
|
|
798
|
+
let quoted = false;
|
|
799
|
+
for (let index = 0; index < csv.length; index++) {
|
|
800
|
+
if (csv[index] !== '"') continue;
|
|
801
|
+
if (quoted && csv[index + 1] === '"') index++;
|
|
802
|
+
else quoted = !quoted;
|
|
803
|
+
}
|
|
804
|
+
return quoted ? { csv: text, footer: [] } : { csv, footer: lines.map((line) => line.slice(2)) };
|
|
776
805
|
}
|
|
777
806
|
|
|
778
807
|
/** CSV with its closing `#` lines after a blank line. */
|
package/src/cli/result.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
type CliTableColumn,
|
|
16
16
|
} from "../utils/cli-output";
|
|
17
17
|
import { serializeCsv } from "../utils/csv";
|
|
18
|
+
import { portableCsv } from "./csv-export";
|
|
18
19
|
import { logFailure } from "../utils/log-failure";
|
|
19
20
|
import { formatUtcTime, isEpochMilliseconds, isZonedIsoDateTime } from "../utils/utc-time";
|
|
20
21
|
import { formatFreshnessLine, withSavedCopy, type ReportFreshness } from "./pane-functions/freshness";
|
|
@@ -732,17 +733,15 @@ export function printCliResult<T, Row extends Record<string, unknown> = Record<s
|
|
|
732
733
|
const serialized = hinted(toFile
|
|
733
734
|
? renderForFile(() => serializeCliResult(cells, options, renderOptions))
|
|
734
735
|
: serializeCliResult(cells, options, renderOptions));
|
|
735
|
-
// A CSV's closing source and note lines go to stderr with the warnings: in the file they are rows of junk to a spreadsheet.
|
|
736
736
|
const { csv, footer } = options.format === "csv" ? splitCsvFooter(serialized) : { csv: serialized, footer: [] };
|
|
737
|
-
const output = csv
|
|
737
|
+
const output = options.format === "csv" ? portableCsv(serialized, result.warnings,
|
|
738
|
+
[...renderOptions.exportNotes ?? [], ...renderOptions.footnote ? [renderOptions.footnote] : []]) : csv;
|
|
738
739
|
if (toFile) fileExport.push(output);
|
|
739
740
|
// Bun's console writer can truncate a large pipe write after stdout has been
|
|
740
741
|
// initialized. The stream queues the remaining bytes until the reader drains.
|
|
741
742
|
else if (output && !process.stdout.write(`${output}\n`)) {
|
|
742
743
|
stdoutWritten = new Promise((resolve) => process.stdout.once("drain", () => resolve()));
|
|
743
744
|
}
|
|
744
|
-
// JSON carries warnings in its envelope. Text, CSV and NDJSON are only the
|
|
745
|
-
// rows, so a warning goes to stderr, out of a file the rows are piped into.
|
|
746
745
|
if (options.format !== "json" && !options.quiet) {
|
|
747
746
|
// Each wraps to a narrow --width, as a note does.
|
|
748
747
|
for (const warning of result.warnings ?? []) {
|
|
@@ -750,8 +749,6 @@ export function printCliResult<T, Row extends Record<string, unknown> = Record<s
|
|
|
750
749
|
}
|
|
751
750
|
}
|
|
752
751
|
if (!options.quiet) for (const line of footer) console.error(line);
|
|
753
|
-
// CSV says what its rows do not in closing `note:` lines, on stderr; NDJSON has no place for one among its rows,
|
|
754
|
-
// so the same notes go to stderr, where the warnings are.
|
|
755
752
|
if (options.format === "ndjson" && !options.quiet) {
|
|
756
753
|
for (const note of exportNdjsonNotes(result, options, renderOptions)) console.error(`note: ${note}`);
|
|
757
754
|
}
|