@quantbrasil/cli 0.1.0-beta.1 → 0.1.0-beta.11

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 (77) hide show
  1. package/README.md +64 -11
  2. package/dist/cli/client.js +4 -0
  3. package/dist/cli/index.d.ts +14 -4
  4. package/dist/cli/index.d.ts.map +1 -1
  5. package/dist/cli/index.js +72 -14
  6. package/dist/cli/prompt.d.ts +1 -0
  7. package/dist/cli/prompt.d.ts.map +1 -1
  8. package/dist/cli/prompt.js +17 -0
  9. package/dist/cli/skills.d.ts +9 -0
  10. package/dist/cli/skills.d.ts.map +1 -1
  11. package/dist/cli/skills.js +68 -4
  12. package/dist/commands/auth.d.ts +18 -0
  13. package/dist/commands/auth.d.ts.map +1 -1
  14. package/dist/commands/auth.js +49 -0
  15. package/dist/commands/cointegration.d.ts +52 -0
  16. package/dist/commands/cointegration.d.ts.map +1 -0
  17. package/dist/commands/cointegration.js +118 -0
  18. package/dist/commands/market.d.ts +1 -0
  19. package/dist/commands/market.d.ts.map +1 -1
  20. package/dist/commands/market.js +17 -1
  21. package/dist/commands/portfolios.d.ts +148 -8
  22. package/dist/commands/portfolios.d.ts.map +1 -1
  23. package/dist/commands/portfolios.js +557 -55
  24. package/dist/commands/rankings.d.ts +82 -0
  25. package/dist/commands/rankings.d.ts.map +1 -0
  26. package/dist/commands/rankings.js +235 -0
  27. package/dist/commands/screening.d.ts +120 -0
  28. package/dist/commands/screening.d.ts.map +1 -0
  29. package/dist/commands/screening.js +361 -0
  30. package/dist/commands/skills.js +7 -7
  31. package/dist/commands/update.d.ts +23 -0
  32. package/dist/commands/update.d.ts.map +1 -0
  33. package/dist/commands/update.js +209 -0
  34. package/dist/index.d.ts +3 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +3 -1
  37. package/dist/vendor/core/capabilities/cointegration.d.ts +52 -0
  38. package/dist/vendor/core/capabilities/cointegration.d.ts.map +1 -0
  39. package/dist/vendor/core/capabilities/cointegration.js +63 -0
  40. package/dist/vendor/core/capabilities/index.d.ts +3 -1
  41. package/dist/vendor/core/capabilities/index.d.ts.map +1 -1
  42. package/dist/vendor/core/capabilities/index.js +3 -1
  43. package/dist/vendor/core/capabilities/market.d.ts +9 -1
  44. package/dist/vendor/core/capabilities/market.d.ts.map +1 -1
  45. package/dist/vendor/core/capabilities/market.js +10 -0
  46. package/dist/vendor/core/capabilities/portfolios.d.ts +452 -56
  47. package/dist/vendor/core/capabilities/portfolios.d.ts.map +1 -1
  48. package/dist/vendor/core/capabilities/portfolios.js +434 -116
  49. package/dist/vendor/core/capabilities/rankings.d.ts +83 -0
  50. package/dist/vendor/core/capabilities/rankings.d.ts.map +1 -0
  51. package/dist/vendor/core/capabilities/rankings.js +96 -0
  52. package/dist/vendor/core/capabilities/registry.d.ts +1380 -414
  53. package/dist/vendor/core/capabilities/registry.d.ts.map +1 -1
  54. package/dist/vendor/core/capabilities/registry.js +6 -2
  55. package/dist/vendor/core/capabilities/screening.d.ts +136 -0
  56. package/dist/vendor/core/capabilities/screening.d.ts.map +1 -0
  57. package/dist/vendor/core/capabilities/screening.js +155 -0
  58. package/dist/vendor/core/capabilities/types.d.ts +1 -1
  59. package/dist/vendor/core/capabilities/types.d.ts.map +1 -1
  60. package/package.json +3 -3
  61. package/skills/quantbrasil/SKILL.md +31 -11
  62. package/skills/quantbrasil/references/cli.md +112 -19
  63. package/skills/quantbrasil/references/cointegration.md +40 -0
  64. package/skills/quantbrasil/references/costs.md +10 -4
  65. package/skills/quantbrasil/references/errors.md +16 -5
  66. package/skills/quantbrasil/references/portfolios.md +114 -0
  67. package/skills/quantbrasil/references/quality-eval-queries.json +147 -0
  68. package/skills/quantbrasil/references/rankings.md +64 -0
  69. package/skills/quantbrasil/references/screening.md +212 -0
  70. package/skills/quantbrasil/references/unsupported.md +9 -2
  71. package/skills/quantbrasil/references/workflows.md +117 -23
  72. package/dist/commands/analytics.d.ts +0 -131
  73. package/dist/commands/analytics.d.ts.map +0 -1
  74. package/dist/commands/analytics.js +0 -291
  75. package/dist/vendor/core/capabilities/analytics.d.ts +0 -187
  76. package/dist/vendor/core/capabilities/analytics.d.ts.map +0 -1
  77. package/dist/vendor/core/capabilities/analytics.js +0 -214
@@ -0,0 +1,82 @@
1
+ import { Command } from "commander";
2
+ import type { JsonValue } from "../vendor/core/index.js";
3
+ import { type CliInvokeContext } from "../cli/client.js";
4
+ import { type TerminalWriter } from "../cli/terminal.js";
5
+ export interface RankingsCommandIO {
6
+ stdout: TerminalWriter;
7
+ }
8
+ export interface RankingsListCommandOptions {
9
+ json?: boolean;
10
+ }
11
+ export interface RankingsCurrentCommandOptions {
12
+ id?: string;
13
+ system?: string;
14
+ top?: string;
15
+ json?: boolean;
16
+ }
17
+ export interface RankingMetricOut {
18
+ [key: string]: JsonValue;
19
+ key: string;
20
+ label: string;
21
+ direction: "asc" | "desc";
22
+ unit: string | null;
23
+ }
24
+ export interface RankingDefinitionOut {
25
+ [key: string]: JsonValue;
26
+ id: string;
27
+ name: string;
28
+ kind: "SYSTEM" | "USER";
29
+ description: string | null;
30
+ order_metric: RankingMetricOut;
31
+ metrics: RankingMetricOut[];
32
+ latest_as_of: string | null;
33
+ total_assets: number | null;
34
+ }
35
+ export interface RankingsListResponse {
36
+ [key: string]: JsonValue;
37
+ ok: boolean;
38
+ system: RankingDefinitionOut[];
39
+ user: RankingDefinitionOut[];
40
+ total: number;
41
+ }
42
+ export interface RankingMetricValueOut {
43
+ [key: string]: JsonValue;
44
+ key: string;
45
+ label: string;
46
+ value: string | number | boolean | null;
47
+ unit: string | null;
48
+ direction: "asc" | "desc";
49
+ }
50
+ export interface RankingCurrentRowOut {
51
+ [key: string]: JsonValue;
52
+ rank: number;
53
+ ticker: string;
54
+ name: string | null;
55
+ order_metric: RankingMetricValueOut;
56
+ score: number | null;
57
+ metrics: Record<string, string | number | boolean | null>;
58
+ }
59
+ export interface RankingCurrentResponse {
60
+ [key: string]: JsonValue;
61
+ ok: boolean;
62
+ summary_markdown: string;
63
+ ranking: RankingDefinitionOut;
64
+ as_of: string | null;
65
+ top_n: number;
66
+ count: number;
67
+ rows: RankingCurrentRowOut[];
68
+ }
69
+ export interface RankingsCommandContext extends CliInvokeContext {
70
+ io?: RankingsCommandIO;
71
+ }
72
+ type JsonRecord = {
73
+ [key: string]: JsonValue;
74
+ };
75
+ export declare function registerRankingsCommands(program: Command, context?: RankingsCommandContext): void;
76
+ export declare function runRankingsListCommand(options: RankingsListCommandOptions, context?: RankingsCommandContext): Promise<void>;
77
+ export declare function runRankingsCurrentCommand(options: RankingsCurrentCommandOptions, context?: RankingsCommandContext): Promise<void>;
78
+ export declare function buildRankingsCurrentInput(options: RankingsCurrentCommandOptions): JsonRecord;
79
+ export declare function formatRankingsListHuman(data: RankingsListResponse, theme?: import("../cli/terminal.js").TerminalTheme): string;
80
+ export declare function formatRankingCurrentHuman(data: RankingCurrentResponse, theme?: import("../cli/terminal.js").TerminalTheme): string;
81
+ export {};
82
+ //# sourceMappingURL=rankings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rankings.d.ts","sourceRoot":"","sources":["../../src/commands/rankings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE9E,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,6BAA6B;IAC5C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb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;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,sBAAsB,EAC5B,KAAK,6CAAsC,GAC1C,MAAM,CAwCR"}
@@ -0,0 +1,235 @@
1
+ import { invokeCliCapability } from "../cli/client.js";
2
+ import { createCliValidationError } from "../cli/errors.js";
3
+ import { createTerminalTheme } from "../cli/terminal.js";
4
+ export function registerRankingsCommands(program, context = {}) {
5
+ const rankingsCommand = program
6
+ .command("rankings")
7
+ .description("Consulta rankings do sistema e rankings do usuário");
8
+ rankingsCommand
9
+ .command("list")
10
+ .description("Lista rankings disponíveis")
11
+ .option("--json", "Exibe saída JSON")
12
+ .action(async (options) => {
13
+ await runRankingsListCommand(options, context);
14
+ });
15
+ rankingsCommand
16
+ .command("current")
17
+ .description("Consulta o topo atual de um ranking")
18
+ .option("--system <slug>", "Slug do ranking do sistema")
19
+ .option("--id <id>", "ID numérico do ranking do usuário")
20
+ .option("--top <n>", "Número de ativos do topo do ranking", "20")
21
+ .option("--json", "Exibe saída JSON")
22
+ .action(async (options) => {
23
+ await runRankingsCurrentCommand(options, context);
24
+ });
25
+ }
26
+ export async function runRankingsListCommand(options, context = {}) {
27
+ const stdout = context.io?.stdout ?? process.stdout;
28
+ const theme = createTerminalTheme(stdout, context.env ?? process.env);
29
+ const response = await invokeCliCapability({
30
+ capability: "rankings.list",
31
+ env: context.env,
32
+ fetch: context.fetch,
33
+ });
34
+ if (options.json) {
35
+ stdout.write(`${JSON.stringify(response.data, null, 2)}\n`);
36
+ return;
37
+ }
38
+ stdout.write(`${formatRankingsListHuman(response.data, theme)}\n`);
39
+ }
40
+ export async function runRankingsCurrentCommand(options, context = {}) {
41
+ const stdout = context.io?.stdout ?? process.stdout;
42
+ const theme = createTerminalTheme(stdout, context.env ?? process.env);
43
+ const response = await invokeCliCapability({
44
+ capability: "rankings.current",
45
+ input: buildRankingsCurrentInput(options),
46
+ env: context.env,
47
+ fetch: context.fetch,
48
+ });
49
+ if (options.json) {
50
+ stdout.write(`${JSON.stringify(response.data, null, 2)}\n`);
51
+ return;
52
+ }
53
+ stdout.write(`${formatRankingCurrentHuman(response.data, theme)}\n`);
54
+ }
55
+ export function buildRankingsCurrentInput(options) {
56
+ const hasId = options.id !== undefined;
57
+ const hasSystem = options.system !== undefined;
58
+ if (Number(hasId) + Number(hasSystem) !== 1) {
59
+ throw createCliValidationError("Use exatamente um seletor: --system ou --id.");
60
+ }
61
+ const input = {
62
+ top_n: parseTopOption(options.top),
63
+ };
64
+ if (hasId) {
65
+ input.user_ranking_id = parsePositiveInteger(options.id, "--id");
66
+ }
67
+ if (hasSystem) {
68
+ input.system_id = normalizeRequiredString(options.system, "--system");
69
+ }
70
+ return input;
71
+ }
72
+ export function formatRankingsListHuman(data, theme = createTerminalTheme(process.stdout)) {
73
+ const lines = [
74
+ theme.label("Rankings"),
75
+ "",
76
+ `${theme.label("Total:")} ${formatInteger(data.total)}`,
77
+ ];
78
+ lines.push("");
79
+ lines.push(...formatRankingGroup("Sistema", data.system, theme));
80
+ lines.push("");
81
+ lines.push(...formatRankingGroup("Meus rankings", data.user, theme));
82
+ return lines.join("\n");
83
+ }
84
+ export function formatRankingCurrentHuman(data, theme = createTerminalTheme(process.stdout)) {
85
+ const lines = [
86
+ theme.label("Ranking atual"),
87
+ "",
88
+ `${theme.bold(data.ranking.name)} ${theme.dim(`(${formatRankingKind(data.ranking.kind)})`)}`,
89
+ formatRankingIdentifierLine(data.ranking, theme),
90
+ ];
91
+ if (data.ranking.kind === "USER" && data.ranking.metrics.length > 0) {
92
+ lines.push(`${theme.label("Fatores:")} ${formatMetricList(data.ranking.metrics)}`);
93
+ lines.push(`${theme.label("Ordenação:")} ${formatMetricDefinition(data.ranking.order_metric)}`);
94
+ }
95
+ else {
96
+ lines.push(`${theme.label("Métrica:")} ${formatMetricDefinition(data.ranking.order_metric)}`);
97
+ }
98
+ lines.push(`${theme.label("Top:")} ${formatInteger(data.top_n)}`, `${theme.label("Ativos retornados:")} ${formatInteger(data.count)}`);
99
+ if (data.as_of) {
100
+ lines.push(`${theme.label("Data:")} ${data.as_of}`);
101
+ }
102
+ if (data.rows.length === 0) {
103
+ lines.push("");
104
+ lines.push(theme.dim("Nenhum ativo retornado."));
105
+ return lines.join("\n");
106
+ }
107
+ lines.push("");
108
+ lines.push(...formatRankingRows(data.rows, data.ranking.order_metric.label));
109
+ return lines.join("\n");
110
+ }
111
+ function formatRankingGroup(title, rankings, theme) {
112
+ const lines = [
113
+ `${theme.label(title)} ${theme.dim(`(${formatInteger(rankings.length)})`)}`,
114
+ ];
115
+ if (rankings.length === 0) {
116
+ lines.push(` ${theme.dim("Nenhum ranking disponível.")}`);
117
+ return lines;
118
+ }
119
+ for (const ranking of rankings) {
120
+ if (ranking.kind === "USER") {
121
+ lines.push(` ${theme.bold(ranking.name)}`);
122
+ lines.push(` ${theme.label("ID:")} ${formatRankingDisplayId(ranking)}`);
123
+ if (ranking.metrics.length > 0) {
124
+ lines.push(` ${theme.label("Fatores:")} ${formatMetricList(ranking.metrics)}`);
125
+ lines.push(` ${theme.label("Ordenação:")} ${formatMetricDefinition(ranking.order_metric)}`);
126
+ }
127
+ else {
128
+ lines.push(` ${theme.label("Métrica:")} ${formatMetricDefinition(ranking.order_metric)}`);
129
+ }
130
+ }
131
+ else {
132
+ lines.push(` ${theme.bold(ranking.id)} - ${ranking.name}`);
133
+ lines.push(` ${theme.label("Métrica:")} ${formatMetricDefinition(ranking.order_metric)}`);
134
+ }
135
+ if (ranking.latest_as_of) {
136
+ lines.push(` ${theme.label("Atualizado em:")} ${ranking.latest_as_of}`);
137
+ }
138
+ if (ranking.total_assets !== null) {
139
+ lines.push(` ${theme.label("Ativos:")} ${formatInteger(ranking.total_assets)}`);
140
+ }
141
+ lines.push(` ${theme.label("Uso:")} ${formatRankingUsage(ranking)}`);
142
+ }
143
+ return lines;
144
+ }
145
+ function formatRankingRows(rows, metricLabel) {
146
+ const metricHeader = truncate(metricLabel, 26);
147
+ const header = `${"#".padEnd(4)}${"Ativo".padEnd(12)}${metricHeader}`;
148
+ const divider = "-".repeat(header.length);
149
+ const lines = [header, divider];
150
+ for (const row of rows) {
151
+ lines.push(`${formatInteger(row.rank).padEnd(4)}${row.ticker.padEnd(12)}${formatMetricValue(row.order_metric)}`);
152
+ }
153
+ return lines;
154
+ }
155
+ function formatRankingUsage(ranking) {
156
+ if (ranking.kind === "USER") {
157
+ return `quantbrasil rankings current --id ${formatRankingDisplayId(ranking)} --top 20`;
158
+ }
159
+ return `quantbrasil rankings current --system ${ranking.id} --top 20`;
160
+ }
161
+ function formatRankingKind(kind) {
162
+ return kind === "SYSTEM" ? "sistema" : "usuário";
163
+ }
164
+ function formatRankingDisplayId(ranking) {
165
+ if (ranking.kind === "USER" && ranking.id.startsWith("user:")) {
166
+ return ranking.id.slice("user:".length);
167
+ }
168
+ return ranking.id;
169
+ }
170
+ function formatRankingIdentifierLine(ranking, theme) {
171
+ if (ranking.kind === "USER") {
172
+ return `${theme.label("ID:")} ${formatRankingDisplayId(ranking)}`;
173
+ }
174
+ return `${theme.label("Sistema:")} ${ranking.id}`;
175
+ }
176
+ function formatMetricList(metrics) {
177
+ return metrics.map(formatMetricDefinition).join(", ");
178
+ }
179
+ function formatMetricDefinition(metric) {
180
+ return `${metric.label} (${formatMetricDirection(metric.direction)})`;
181
+ }
182
+ function formatMetricDirection(direction) {
183
+ return direction === "asc" ? "menor é melhor" : "maior é melhor";
184
+ }
185
+ function formatMetricValue(metric) {
186
+ if (metric.value === null) {
187
+ return "-";
188
+ }
189
+ if (typeof metric.value === "number") {
190
+ if (metric.unit === "ratio") {
191
+ return `${formatNumber(metric.value * 100)}%`;
192
+ }
193
+ return formatNumber(metric.value);
194
+ }
195
+ return String(metric.value);
196
+ }
197
+ function parseTopOption(rawTop) {
198
+ if (rawTop === undefined) {
199
+ return 20;
200
+ }
201
+ return parsePositiveInteger(rawTop, "--top");
202
+ }
203
+ function parsePositiveInteger(rawValue, label) {
204
+ const normalized = normalizeRequiredString(rawValue, label);
205
+ const parsed = Number.parseInt(normalized, 10);
206
+ if (!Number.isInteger(parsed) ||
207
+ parsed <= 0 ||
208
+ String(parsed) !== normalized) {
209
+ throw createCliValidationError(`${label} deve ser um inteiro positivo.`);
210
+ }
211
+ return parsed;
212
+ }
213
+ function normalizeRequiredString(rawValue, label) {
214
+ const normalized = rawValue?.trim();
215
+ if (!normalized) {
216
+ throw createCliValidationError(`${label} não pode ser vazio.`);
217
+ }
218
+ return normalized;
219
+ }
220
+ function formatInteger(value) {
221
+ return new Intl.NumberFormat("pt-BR", {
222
+ maximumFractionDigits: 0,
223
+ }).format(value);
224
+ }
225
+ function formatNumber(value) {
226
+ return new Intl.NumberFormat("pt-BR", {
227
+ maximumFractionDigits: 4,
228
+ }).format(value);
229
+ }
230
+ function truncate(value, maxLength) {
231
+ if (value.length <= maxLength) {
232
+ return value;
233
+ }
234
+ return `${value.slice(0, maxLength - 3)}...`;
235
+ }
@@ -0,0 +1,120 @@
1
+ import { Command } from "commander";
2
+ import type { JsonValue } from "../vendor/core/index.js";
3
+ import { type CliInvokeContext } from "../cli/client.js";
4
+ import { type TerminalWriter } from "../cli/terminal.js";
5
+ export interface ScreeningCommandIO {
6
+ stdout: TerminalWriter;
7
+ }
8
+ export interface ScreeningUniversesCommandOptions {
9
+ json?: boolean;
10
+ }
11
+ export interface ScreeningIndicatorsCommandOptions {
12
+ json?: boolean;
13
+ }
14
+ export interface ScreeningRunCommandOptions {
15
+ system?: string;
16
+ watchlist?: string;
17
+ holding?: string;
18
+ queryFile?: string;
19
+ limit?: string;
20
+ sort?: string;
21
+ json?: boolean;
22
+ }
23
+ export interface ScreeningUniverseOut {
24
+ [key: string]: JsonValue;
25
+ id: number;
26
+ name: string;
27
+ kind: "SYSTEM" | "WATCHLIST" | "HOLDING";
28
+ slug: string | null;
29
+ symbol_count: number;
30
+ }
31
+ export interface ScreeningUniversesResponse {
32
+ [key: string]: JsonValue;
33
+ ok: boolean;
34
+ system: ScreeningUniverseOut[];
35
+ watchlists: ScreeningUniverseOut[];
36
+ holdings: ScreeningUniverseOut[];
37
+ total: number;
38
+ }
39
+ export type ScreeningIndicatorScalar = string | number | boolean;
40
+ export interface ScreeningIndicatorParamOut {
41
+ [key: string]: JsonValue;
42
+ name: string;
43
+ type: "integer" | "number" | "enum" | "string" | "boolean";
44
+ required: boolean;
45
+ default: ScreeningIndicatorScalar | null;
46
+ description: string;
47
+ enum_values: string[] | null;
48
+ examples: ScreeningIndicatorScalar[];
49
+ }
50
+ export interface ScreeningIndicatorRef {
51
+ [key: string]: JsonValue;
52
+ name: string;
53
+ timeframe: string;
54
+ offset: number;
55
+ params: Record<string, JsonValue>;
56
+ }
57
+ export interface ScreeningIndicatorExampleOut {
58
+ [key: string]: JsonValue;
59
+ label: string;
60
+ description: string;
61
+ indicator: ScreeningIndicatorRef;
62
+ }
63
+ export interface ScreeningIndicatorOut {
64
+ [key: string]: JsonValue;
65
+ name: string;
66
+ display_name: string;
67
+ description: string;
68
+ timeframes: string[];
69
+ params: ScreeningIndicatorParamOut[];
70
+ examples: ScreeningIndicatorExampleOut[];
71
+ }
72
+ export interface ScreeningIndicatorsResponse {
73
+ [key: string]: JsonValue;
74
+ ok: boolean;
75
+ indicators: ScreeningIndicatorOut[];
76
+ operators: string[];
77
+ }
78
+ export interface IndicatorResult {
79
+ [key: string]: JsonValue;
80
+ value: number;
81
+ display_name: string;
82
+ unit: string | null;
83
+ context: {
84
+ [key: string]: JsonValue;
85
+ } | null;
86
+ }
87
+ export interface ScreenerResultItem {
88
+ [key: string]: JsonValue;
89
+ ticker: string;
90
+ price: number;
91
+ indicators: Record<string, IndicatorResult>;
92
+ }
93
+ export interface ScreenerResponse {
94
+ [key: string]: JsonValue;
95
+ count: number;
96
+ results: ScreenerResultItem[];
97
+ }
98
+ export interface ScreeningRunResponse {
99
+ [key: string]: JsonValue;
100
+ ok: boolean;
101
+ summary_markdown: string;
102
+ universe: ScreeningUniverseOut;
103
+ result: ScreenerResponse;
104
+ }
105
+ export interface ScreeningCommandContext extends CliInvokeContext {
106
+ io?: ScreeningCommandIO;
107
+ }
108
+ type JsonRecord = {
109
+ [key: string]: JsonValue;
110
+ };
111
+ export declare function registerScreeningCommands(program: Command, context?: ScreeningCommandContext): void;
112
+ export declare function runScreeningUniversesCommand(options: ScreeningUniversesCommandOptions, context?: ScreeningCommandContext): Promise<void>;
113
+ export declare function runScreeningIndicatorsCommand(options: ScreeningIndicatorsCommandOptions, context?: ScreeningCommandContext): Promise<void>;
114
+ export declare function runScreeningRunCommand(options: ScreeningRunCommandOptions, context?: ScreeningCommandContext): Promise<void>;
115
+ export declare function buildScreeningRunInput(options: ScreeningRunCommandOptions): Promise<JsonRecord>;
116
+ export declare function formatScreeningUniversesHuman(data: ScreeningUniversesResponse, theme?: import("../cli/terminal.js").TerminalTheme): string;
117
+ export declare function formatScreeningIndicatorsHuman(data: ScreeningIndicatorsResponse, theme?: import("../cli/terminal.js").TerminalTheme): string;
118
+ export declare function formatScreeningRunHuman(data: ScreeningRunResponse, theme?: import("../cli/terminal.js").TerminalTheme): string;
119
+ export {};
120
+ //# sourceMappingURL=screening.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screening.d.ts","sourceRoot":"","sources":["../../src/commands/screening.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE9E,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,gCAAgC;IAC/C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,iCAAiC;IAChD,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC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