@mintlify/cli 4.0.1379 → 4.0.1381

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.
@@ -0,0 +1,108 @@
1
+ import { checkbox } from '@inquirer/prompts';
2
+ import { addLog, ErrorLog, WarningLog } from '@mintlify/previewing';
3
+ import { Text } from 'ink';
4
+ import os from 'os';
5
+ import React from 'react';
6
+
7
+ import { trackEvent } from '../telemetry/track.js';
8
+ import {
9
+ ALL_CLIENT_NAMES,
10
+ CLIENTS,
11
+ detectClients,
12
+ type ClientName,
13
+ type Scope,
14
+ type SetupContext,
15
+ } from './clients.js';
16
+ import { setupClient, type ClientSetupResult } from './engine.js';
17
+
18
+ export interface IndexSetupOptions extends Partial<Record<ClientName, boolean>> {
19
+ project?: boolean;
20
+ yes?: boolean;
21
+ }
22
+
23
+ export function resolveExplicitClients(options: IndexSetupOptions): ClientName[] {
24
+ return ALL_CLIENT_NAMES.filter((name) => options[name] === true);
25
+ }
26
+
27
+ async function promptClients(detected: ClientName[]): Promise<ClientName[] | undefined> {
28
+ try {
29
+ return await checkbox({
30
+ message: 'Which coding agents do you want to set up?',
31
+ loop: false,
32
+ choices: ALL_CLIENT_NAMES.map((name) => ({
33
+ name: CLIENTS[name].displayName,
34
+ value: name,
35
+ checked: detected.includes(name),
36
+ })),
37
+ });
38
+ } catch {
39
+ return undefined;
40
+ }
41
+ }
42
+
43
+ function logResult(result: ClientSetupResult): void {
44
+ addLog(<Text bold>{result.displayName}</Text>);
45
+ if (result.mcpStatus === 'failed') {
46
+ addLog(<ErrorLog message={` MCP server failed: ${result.mcpDetail}`} />);
47
+ } else {
48
+ addLog(
49
+ <Text>
50
+ {' '}MCP server {result.mcpStatus} <Text dimColor>{result.mcpDetail}</Text>
51
+ </Text>
52
+ );
53
+ }
54
+ if (result.ruleStatus === 'failed') {
55
+ addLog(<ErrorLog message={` Rule failed: ${result.ruleDetail}`} />);
56
+ } else if (result.ruleStatus !== 'none') {
57
+ addLog(
58
+ <Text>
59
+ {' '}Rule {result.ruleStatus} <Text dimColor>{result.ruleDetail}</Text>
60
+ </Text>
61
+ );
62
+ }
63
+ }
64
+
65
+ export async function runIndexSetup(options: IndexSetupOptions): Promise<number> {
66
+ const ctx: SetupContext = {
67
+ home: os.homedir(),
68
+ cwd: process.cwd(),
69
+ platform: process.platform,
70
+ env: process.env,
71
+ };
72
+ const scope: Scope = options.project === true ? 'project' : 'global';
73
+ let selected = resolveExplicitClients(options);
74
+ if (selected.length === 0) {
75
+ const detected = await detectClients(ctx);
76
+ if (options.yes === true) {
77
+ if (detected.length === 0) {
78
+ addLog(
79
+ <ErrorLog message="no coding agents detected; pass flags like --claude or --cursor" />
80
+ );
81
+ return 1;
82
+ }
83
+ selected = detected;
84
+ } else {
85
+ const picked = await promptClients(detected);
86
+ if (picked === undefined || picked.length === 0) {
87
+ addLog(<WarningLog message="setup cancelled" />);
88
+ return 1;
89
+ }
90
+ selected = picked;
91
+ }
92
+ }
93
+ const results: ClientSetupResult[] = [];
94
+ for (const name of selected) {
95
+ results.push(await setupClient(CLIENTS[name], scope, ctx));
96
+ }
97
+ for (const result of results) {
98
+ logResult(result);
99
+ }
100
+ const succeeded = results.filter((result) => result.mcpStatus !== 'failed');
101
+ addLog(
102
+ <Text>
103
+ Mintlify index MCP set up for {succeeded.length}/{results.length} agents
104
+ </Text>
105
+ );
106
+ void trackEvent('cli.index.completed', { clients: selected, scope });
107
+ return succeeded.length > 0 ? 0 : 1;
108
+ }