@mintlify/cli 4.0.1762 → 4.0.1763

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,146 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { checkbox } from '@inquirer/prompts';
11
+ import { spawn } from 'node:child_process';
12
+ import { existsSync } from 'node:fs';
13
+ import os from 'node:os';
14
+ import path from 'node:path';
15
+ import { stripVTControlCharacters } from 'node:util';
16
+ import { ADMIN_MCP_NAME, ADMIN_MCP_URL, prepareMcpConfig, writeMcpConfig, } from './agent-setup-config.js';
17
+ import { detectAgent } from './agent.js';
18
+ export const SETUP_AGENTS = ['claude-code', 'codex', 'cursor'];
19
+ const AGENT_LABELS = {
20
+ 'claude-code': 'Claude Code',
21
+ codex: 'Codex',
22
+ cursor: 'Cursor',
23
+ };
24
+ function isSetupAgent(value) {
25
+ return SETUP_AGENTS.some((agent) => agent === value);
26
+ }
27
+ function detectedAgents() {
28
+ const homeDir = os.homedir();
29
+ const current = detectAgent();
30
+ return SETUP_AGENTS.filter((agent) => {
31
+ if (agent === 'codex') {
32
+ return (current === 'codex_cli' ||
33
+ existsSync(process.env.CODEX_HOME || path.join(homeDir, '.codex')));
34
+ }
35
+ if (agent === 'claude-code') {
36
+ return (current === 'claude_code' ||
37
+ existsSync(process.env.CLAUDE_CONFIG_DIR || path.join(homeDir, '.claude')));
38
+ }
39
+ return (current === 'cursor' || current === 'cursor-cli' || existsSync(path.join(homeDir, '.cursor')));
40
+ });
41
+ }
42
+ export function installSkills(agents, global) {
43
+ const args = [
44
+ '--yes',
45
+ 'skills@1.7.4',
46
+ 'add',
47
+ 'https://mintlify.com/docs',
48
+ '--agent',
49
+ ...agents,
50
+ '--yes',
51
+ ];
52
+ if (global)
53
+ args.push('--global');
54
+ return new Promise((resolve, reject) => {
55
+ const child = spawn('npx', args, {
56
+ stdio: ['ignore', 'pipe', 'pipe'],
57
+ shell: process.platform === 'win32',
58
+ });
59
+ let output = '';
60
+ const recordOutput = (chunk) => {
61
+ output = (output + chunk.toString()).slice(-65536);
62
+ };
63
+ child.stdout.on('data', (chunk) => {
64
+ recordOutput(chunk);
65
+ process.stdout.write(chunk.toString());
66
+ });
67
+ child.stderr.on('data', (chunk) => {
68
+ recordOutput(chunk);
69
+ process.stderr.write(chunk.toString());
70
+ });
71
+ child.on('error', () => reject(new Error('Could not run npx. Install npm and run setup again.')));
72
+ child.on('close', (code, signal) => {
73
+ if (code !== 0 || /Failed to install\s+\d+/.test(stripVTControlCharacters(output))) {
74
+ reject(new Error(`Skills installation failed (${signal !== null && signal !== void 0 ? signal : code}). Review the installer output and run setup again.`));
75
+ }
76
+ else {
77
+ resolve();
78
+ }
79
+ });
80
+ });
81
+ }
82
+ export function setupAgent(options) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ var _a;
85
+ const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
86
+ if (major < 22 || (major === 22 && minor < 20)) {
87
+ throw new Error('mint agent setup requires Node.js 22.20 or later to install skills. Upgrade Node.js and try again.');
88
+ }
89
+ const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
90
+ let agents = [];
91
+ for (const agent of (_a = options.agents) !== null && _a !== void 0 ? _a : []) {
92
+ if (!isSetupAgent(agent))
93
+ throw new Error(`Unsupported agent: ${agent}`);
94
+ if (!agents.includes(agent))
95
+ agents.push(agent);
96
+ }
97
+ if (agents.length === 0) {
98
+ const detected = detectedAgents();
99
+ if (!interactive) {
100
+ agents = detected;
101
+ }
102
+ else {
103
+ agents = yield checkbox({
104
+ message: 'Which agents should use Mintlify?',
105
+ choices: SETUP_AGENTS.map((agent) => ({
106
+ name: AGENT_LABELS[agent],
107
+ value: agent,
108
+ checked: detected.includes(agent),
109
+ })),
110
+ required: true,
111
+ });
112
+ }
113
+ }
114
+ if (agents.length === 0) {
115
+ throw new Error('No supported agents detected. Pass --agent claude-code, codex, or cursor.');
116
+ }
117
+ const location = { cwd: process.cwd(), homeDir: os.homedir(), global: options.global };
118
+ const plans = yield Promise.all(agents.map((agent) => prepareMcpConfig(agent, location)));
119
+ const scope = options.global ? 'your user account' : 'this project';
120
+ process.stdout.write(`Setting up Mintlify skills and Admin MCP for ${scope}.\n`);
121
+ yield installSkills(agents, options.global);
122
+ for (const plan of plans) {
123
+ yield writeMcpConfig(plan);
124
+ const action = plan.contents === undefined ? 'Already configured' : 'Configured';
125
+ process.stdout.write(`${action}: ${plan.path}\n`);
126
+ }
127
+ process.stdout.write('\nAdmin MCP is configured. Complete OAuth sign-in to grant account and project access:\n');
128
+ for (const agent of agents) {
129
+ if (agent === 'codex') {
130
+ let command = `codex mcp login ${ADMIN_MCP_NAME}`;
131
+ if (!options.global) {
132
+ const config = `mcp_servers.${ADMIN_MCP_NAME}.url='${ADMIN_MCP_URL}'`;
133
+ command = `codex -c "${config}" mcp login ${ADMIN_MCP_NAME}`;
134
+ }
135
+ process.stdout.write(` Codex: run ${command}. Trust the project before using its MCP configuration.\n`);
136
+ }
137
+ else if (agent === 'claude-code') {
138
+ process.stdout.write(` Claude Code: open /mcp and authenticate ${ADMIN_MCP_NAME}. Approve the project server if prompted.\n`);
139
+ }
140
+ else {
141
+ process.stdout.write(` Cursor: open MCP settings and connect ${ADMIN_MCP_NAME}.\n`);
142
+ }
143
+ }
144
+ process.stdout.write('Setup: https://mintlify.com/docs/ai/mintlify-mcp\n');
145
+ });
146
+ }
package/bin/cli.js CHANGED
@@ -16,6 +16,7 @@ import { hideBin } from 'yargs/helpers';
16
16
  import { accessibilityCheck } from './accessibilityCheck.js';
17
17
  import { addDomain } from './addDomain.js';
18
18
  import { claimDeployment, createAgentClaimLink } from './agent-claim.js';
19
+ import { SETUP_AGENTS, setupAgent } from './agent-setup.js';
19
20
  import { analyticsBuilder } from './analytics/index.js';
20
21
  import { brokenLinksHandler } from './brokenLinks.js';
21
22
  import { comingSoon } from './comingSoon.js';
@@ -100,6 +101,35 @@ export const cli = ({ packageName = 'mint' }) => {
100
101
  .middleware(checkNodeVersion)
101
102
  .middleware(suppressConsoleWarnings)
102
103
  .middleware(telemetryMiddleware)
104
+ .command('agent', 'Set up AI coding agents for Mintlify', (yargs) => yargs
105
+ .command('setup', 'Install Mintlify skills and configure Admin MCP', (yargs) => yargs
106
+ .exitProcess(false)
107
+ .option('agent', {
108
+ alias: 'a',
109
+ type: 'string',
110
+ array: true,
111
+ choices: SETUP_AGENTS,
112
+ description: 'Agents to configure (defaults to interactive selection)',
113
+ })
114
+ .option('global', {
115
+ alias: 'g',
116
+ type: 'boolean',
117
+ default: false,
118
+ description: 'Set up agents for your user account instead of this project',
119
+ })
120
+ .example('$0 agent setup', 'Choose agents and set up the current project')
121
+ .example('$0 agent setup --agent codex --global', 'Set up Codex for your user account')
122
+ .epilog('Requires Node.js 22.20 or later and npm. Admin MCP requires a separate OAuth sign-in in each agent.'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
123
+ try {
124
+ yield setupAgent({ agents: argv.agent, global: argv.global });
125
+ yield terminate(0);
126
+ }
127
+ catch (error) {
128
+ process.stderr.write(`${error instanceof Error ? error.message : 'Agent setup failed.'}\n`);
129
+ yield terminate(1);
130
+ }
131
+ }))
132
+ .demandCommand(1, 'Run mint agent setup to configure your coding agents.'))
103
133
  .command('claim', 'Claim a site created with mint deploy', (yargs) => yargs
104
134
  .option('email', { type: 'string', description: 'User email for a claim link' })
105
135
  .option('code', {