@mintlify/cli 4.0.1762 → 4.0.1764

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 (49) hide show
  1. package/README.md +18 -0
  2. package/__test__/agent-setup-config.test.ts +314 -0
  3. package/__test__/agent-setup.test.ts +207 -0
  4. package/__test__/migrate.test.ts +186 -0
  5. package/__test__/validateRules.test.ts +36 -0
  6. package/bin/agent-setup-config.js +141 -0
  7. package/bin/agent-setup.js +146 -0
  8. package/bin/cli.js +65 -0
  9. package/bin/migrate.js +54 -0
  10. package/bin/tsconfig.build.tsbuildinfo +1 -1
  11. package/bin/validate/files.js +16 -4
  12. package/bin/validate/mdx.js +1 -1
  13. package/bin/welcome.js +1 -0
  14. package/migrate/index.md +56 -0
  15. package/migrate/sources/confluence.md +120 -0
  16. package/migrate/sources/docsify.md +128 -0
  17. package/migrate/sources/document360.md +117 -0
  18. package/migrate/sources/docus.md +136 -0
  19. package/migrate/sources/docusaurus.md +143 -0
  20. package/migrate/sources/fern.md +130 -0
  21. package/migrate/sources/fumadocs.md +141 -0
  22. package/migrate/sources/gitbook.md +120 -0
  23. package/migrate/sources/github-wiki.md +90 -0
  24. package/migrate/sources/jekyll.md +104 -0
  25. package/migrate/sources/mdbook.md +98 -0
  26. package/migrate/sources/mkdocs.md +113 -0
  27. package/migrate/sources/nextra.md +144 -0
  28. package/migrate/sources/notion.md +99 -0
  29. package/migrate/sources/nuxt.md +113 -0
  30. package/migrate/sources/pdf.md +99 -0
  31. package/migrate/sources/readme.md +118 -0
  32. package/migrate/sources/redocly.md +114 -0
  33. package/migrate/sources/starlight.md +136 -0
  34. package/migrate/sources/vitepress.md +143 -0
  35. package/migrate/sources/vuepress.md +153 -0
  36. package/migrate/topics/api.md +76 -0
  37. package/migrate/topics/changelog.md +47 -0
  38. package/migrate/topics/conversion.md +194 -0
  39. package/migrate/topics/discovery.md +93 -0
  40. package/migrate/topics/navigation.md +82 -0
  41. package/migrate/topics/verify.md +58 -0
  42. package/package.json +12 -10
  43. package/src/agent-setup-config.ts +144 -0
  44. package/src/agent-setup.ts +165 -0
  45. package/src/cli.tsx +91 -0
  46. package/src/migrate.ts +76 -0
  47. package/src/validate/files.ts +23 -3
  48. package/src/validate/mdx.ts +1 -1
  49. package/src/welcome.ts +1 -0
package/README.md CHANGED
@@ -1,3 +1,21 @@
1
1
  # @mintlify/cli
2
2
 
3
3
  The Mintlify CLI. See [mintlify](https://www.npmjs.com/package/mintlify) for more documentation.
4
+
5
+ ## Agent setup
6
+
7
+ Run `mint agent setup` to install [Mintlify skills](https://mintlify.com/docs/ai/skillmd) and configure the [Admin MCP](https://mintlify.com/docs/ai/mintlify-mcp) for Claude Code, Codex, or Cursor. The command requires Node.js 22.20 or later and npm.
8
+
9
+ ```sh
10
+ mint agent setup
11
+ mint agent setup --agent claude-code codex cursor
12
+ mint agent setup --agent codex --global
13
+ ```
14
+
15
+ Setup defaults to the current project. Use `--global` for your user account. Pass `--agent` to configure specific agents directly. Otherwise, interactive setup lets you choose agents, with detected agents selected by default. Without a terminal, setup uses detected agents and requires `--agent` if none are detected.
16
+
17
+ Skills are installed with `npx --yes skills@1.7.4 add https://mintlify.com/docs`, using the selected agents and scope. Rerunning setup refreshes these downloaded skills and replaces local edits to them.
18
+
19
+ Admin MCP uses the server name `mintlify-admin` and URL `https://mcp.mintlify.com`. Setup preserves existing configuration and skips a matching server entry. A conflicting entry or invalid configuration stops setup before skills are installed. Codex configurations with an inline `mcp_servers` table need manual setup, as do global Claude Code configurations using `CLAUDE_CONFIG_DIR`.
20
+
21
+ After configuration, complete OAuth sign-in in each agent to grant access to your Mintlify account and projects. In Claude Code, use `/mcp`; in Cursor, connect the server in MCP settings. For Codex project setup, the printed login command passes the server URL explicitly because some CLI versions do not read project configuration for `mcp login`. Global Codex setup uses `codex mcp login mintlify-admin`. Project configurations may require trusting the project and approving the server first. The command does not reuse `mint login` credentials or complete OAuth on your behalf.
@@ -0,0 +1,314 @@
1
+ import { parse as parseJsonc } from 'jsonc-parser';
2
+ import fs from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { parse as parseToml } from 'smol-toml';
6
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
+
8
+ import {
9
+ ADMIN_MCP_NAME,
10
+ ADMIN_MCP_URL,
11
+ prepareMcpConfig,
12
+ writeMcpConfig,
13
+ type SetupAgent,
14
+ } from '../src/agent-setup-config.js';
15
+
16
+ let directory: string;
17
+ let cwd: string;
18
+ let homeDir: string;
19
+
20
+ const projectPaths: [SetupAgent, string][] = [
21
+ ['claude-code', '.mcp.json'],
22
+ ['codex', '.codex/config.toml'],
23
+ ['cursor', '.cursor/mcp.json'],
24
+ ];
25
+
26
+ const globalPaths: [SetupAgent, string][] = [
27
+ ['claude-code', '.claude.json'],
28
+ ['codex', '.codex/config.toml'],
29
+ ['cursor', '.cursor/mcp.json'],
30
+ ];
31
+
32
+ function options(global = false, env: NodeJS.ProcessEnv = {}) {
33
+ return { cwd, homeDir, global, env };
34
+ }
35
+
36
+ async function fixture(filePath: string, contents: string) {
37
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
38
+ await fs.writeFile(filePath, contents);
39
+ }
40
+
41
+ beforeEach(async () => {
42
+ directory = await fs.mkdtemp(path.join(os.tmpdir(), 'mint-agent-setup-config-'));
43
+ cwd = path.join(directory, 'project');
44
+ homeDir = path.join(directory, 'home');
45
+ await fs.mkdir(cwd);
46
+ await fs.mkdir(homeDir);
47
+ });
48
+
49
+ afterEach(async () => {
50
+ await fs.rm(directory, { recursive: true, force: true });
51
+ });
52
+
53
+ describe('agent setup MCP configuration', () => {
54
+ it.each(projectPaths)(
55
+ 'prepares project configuration for %s without writing it',
56
+ async (agent, relativePath) => {
57
+ const plan = await prepareMcpConfig(agent, options());
58
+
59
+ expect(plan.path).toBe(path.join(cwd, relativePath));
60
+ expect(plan.original).toBeUndefined();
61
+ expect(plan.contents).toEqual(expect.any(String));
62
+ await expect(fs.readFile(plan.path, 'utf8')).rejects.toThrow();
63
+
64
+ if (plan.contents === undefined) throw new Error('Missing prepared configuration');
65
+ if (agent === 'codex') {
66
+ expect(parseToml(plan.contents)).toMatchObject({
67
+ mcp_servers: { [ADMIN_MCP_NAME]: { url: ADMIN_MCP_URL } },
68
+ });
69
+ return;
70
+ }
71
+
72
+ const expectedServer: { url: string; type?: string } = { url: ADMIN_MCP_URL };
73
+ if (agent === 'claude-code') expectedServer.type = 'http';
74
+ expect(parseJsonc(plan.contents)).toEqual({
75
+ mcpServers: { [ADMIN_MCP_NAME]: expectedServer },
76
+ });
77
+ }
78
+ );
79
+
80
+ it.each(globalPaths)(
81
+ 'uses the user configuration path for global %s setup',
82
+ async (agent, relativePath) => {
83
+ const plan = await prepareMcpConfig(agent, options(true));
84
+
85
+ expect(plan.path).toBe(path.join(homeDir, relativePath));
86
+ expect(plan.original).toBeUndefined();
87
+ expect(plan.contents).toContain(ADMIN_MCP_URL);
88
+ }
89
+ );
90
+
91
+ it('honors CODEX_HOME for global setup while retaining project scope', async () => {
92
+ const codexHome = path.join(directory, 'custom-codex');
93
+ const env = { CODEX_HOME: codexHome };
94
+
95
+ const globalPlan = await prepareMcpConfig('codex', options(true, env));
96
+ const projectPlan = await prepareMcpConfig('codex', options(false, env));
97
+
98
+ expect(globalPlan.path).toBe(path.join(codexHome, 'config.toml'));
99
+ expect(projectPlan.path).toBe(path.join(cwd, '.codex/config.toml'));
100
+ });
101
+
102
+ it('refuses an unsupported Claude global directory without blocking project setup', async () => {
103
+ const env = { CLAUDE_CONFIG_DIR: path.join(directory, 'custom-claude') };
104
+
105
+ await expect(prepareMcpConfig('claude-code', options(true, env))).rejects.toThrow();
106
+ const projectPlan = await prepareMcpConfig('claude-code', options(false, env));
107
+ expect(projectPlan.path).toBe(path.join(cwd, '.mcp.json'));
108
+ });
109
+
110
+ it.each(['claude-code', 'cursor'])(
111
+ 'preserves JSONC comments, trailing commas, and other %s settings',
112
+ async (client) => {
113
+ const agent = projectPaths.find(([name]) => name === client);
114
+ if (agent === undefined) throw new Error('Missing test agent');
115
+ const [name, relativePath] = agent;
116
+ const original = `{
117
+ // Personal preferences
118
+ "theme": "dark",
119
+ "mcpServers": {
120
+ "other": { "url": "https://example.com/mcp", },
121
+ },
122
+ }
123
+ `;
124
+ await fixture(path.join(cwd, relativePath), original);
125
+
126
+ const plan = await prepareMcpConfig(name, options());
127
+
128
+ expect(plan.original).toBe(original);
129
+ expect(plan.contents).toContain('// Personal preferences');
130
+ if (plan.contents === undefined) throw new Error('Missing prepared configuration');
131
+ expect(parseJsonc(plan.contents)).toMatchObject({
132
+ theme: 'dark',
133
+ mcpServers: {
134
+ other: { url: 'https://example.com/mcp' },
135
+ [ADMIN_MCP_NAME]: { url: ADMIN_MCP_URL },
136
+ },
137
+ });
138
+ expect(await fs.readFile(plan.path, 'utf8')).toBe(original);
139
+ }
140
+ );
141
+
142
+ it('appends Codex settings while preserving existing TOML text and tables', async () => {
143
+ const original =
144
+ '# Personal preferences\nmodel = "example-model"\n\n[mcp_servers.other]\nurl = "https://example.com/mcp"\n';
145
+ await fixture(path.join(cwd, '.codex/config.toml'), original);
146
+
147
+ const plan = await prepareMcpConfig('codex', options());
148
+
149
+ expect(plan.original).toBe(original);
150
+ expect(plan.contents?.startsWith(original)).toBe(true);
151
+ if (plan.contents === undefined) throw new Error('Missing prepared configuration');
152
+ expect(parseToml(plan.contents)).toMatchObject({
153
+ model: 'example-model',
154
+ mcp_servers: {
155
+ other: { url: 'https://example.com/mcp' },
156
+ [ADMIN_MCP_NAME]: { url: ADMIN_MCP_URL },
157
+ },
158
+ });
159
+ });
160
+
161
+ it.each(['claude-code', 'cursor'])(
162
+ 'skips a matching %s server without changing extra fields',
163
+ async (client) => {
164
+ const agent = projectPaths.find(([name]) => name === client);
165
+ if (agent === undefined) throw new Error('Missing test agent');
166
+ const [name, relativePath] = agent;
167
+ const original = JSON.stringify({
168
+ mcpServers: {
169
+ [ADMIN_MCP_NAME]: {
170
+ url: ADMIN_MCP_URL,
171
+ type: 'http',
172
+ disabled: true,
173
+ headers: { Example: 'value' },
174
+ },
175
+ },
176
+ });
177
+ await fixture(path.join(cwd, relativePath), original);
178
+
179
+ const plan = await prepareMcpConfig(name, options());
180
+
181
+ expect(plan.original).toBe(original);
182
+ expect(plan.contents).toBeUndefined();
183
+ await writeMcpConfig(plan);
184
+ expect(await fs.readFile(plan.path, 'utf8')).toBe(original);
185
+ }
186
+ );
187
+
188
+ it('skips a matching Codex server without enabling or rewriting it', async () => {
189
+ const original = `[mcp_servers.${ADMIN_MCP_NAME}]\nurl = "${ADMIN_MCP_URL}"\nenabled = false\nstartup_timeout_sec = 20\n`;
190
+ await fixture(path.join(cwd, '.codex/config.toml'), original);
191
+
192
+ const plan = await prepareMcpConfig('codex', options());
193
+
194
+ expect(plan.original).toBe(original);
195
+ expect(plan.contents).toBeUndefined();
196
+ await writeMcpConfig(plan);
197
+ expect(await fs.readFile(plan.path, 'utf8')).toBe(original);
198
+ });
199
+
200
+ it.each([undefined, 'stdio'])('rejects an invalid Claude server transport %s', async (type) => {
201
+ const original = JSON.stringify({
202
+ mcpServers: { [ADMIN_MCP_NAME]: { url: ADMIN_MCP_URL, type } },
203
+ });
204
+ await fixture(path.join(cwd, '.mcp.json'), original);
205
+
206
+ await expect(prepareMcpConfig('claude-code', options())).rejects.toThrow('type');
207
+ expect(await fs.readFile(path.join(cwd, '.mcp.json'), 'utf8')).toBe(original);
208
+ });
209
+
210
+ it('detects changes to a server that was already configured', async () => {
211
+ const original = `[mcp_servers.${ADMIN_MCP_NAME}]\nurl = "${ADMIN_MCP_URL}"\n`;
212
+ const filePath = path.join(cwd, '.codex/config.toml');
213
+ await fixture(filePath, original);
214
+ const plan = await prepareMcpConfig('codex', options());
215
+ await fs.writeFile(filePath, '# Changed during installation\n');
216
+
217
+ await expect(writeMcpConfig(plan)).rejects.toThrow('changed during setup');
218
+ expect(await fs.readFile(filePath, 'utf8')).toBe('# Changed during installation\n');
219
+ });
220
+
221
+ it.each([
222
+ { url: 'https://example.com/different' },
223
+ { command: 'example-server', args: ['serve'] },
224
+ ])('refuses a conflicting JSON server %j', async (server) => {
225
+ for (const [agent, relativePath] of projectPaths) {
226
+ if (agent === 'codex') continue;
227
+ const original = JSON.stringify({ mcpServers: { [ADMIN_MCP_NAME]: server } });
228
+ const filePath = path.join(cwd, relativePath);
229
+ await fixture(filePath, original);
230
+
231
+ await expect(prepareMcpConfig(agent, options())).rejects.toThrow();
232
+ expect(await fs.readFile(filePath, 'utf8')).toBe(original);
233
+ }
234
+ });
235
+
236
+ it.each([
237
+ `url = "https://example.com/different"`,
238
+ `command = "example-server"\nargs = ["serve"]`,
239
+ ])('refuses a conflicting Codex server with %s', async (server) => {
240
+ const original = `[mcp_servers.${ADMIN_MCP_NAME}]\n${server}\n`;
241
+ const filePath = path.join(cwd, '.codex/config.toml');
242
+ await fixture(filePath, original);
243
+
244
+ await expect(prepareMcpConfig('codex', options())).rejects.toThrow();
245
+ expect(await fs.readFile(filePath, 'utf8')).toBe(original);
246
+ });
247
+
248
+ it.each(['{', '[]', '{"mcpServers": []}', '{"mcpServers": null}'])(
249
+ 'rejects malformed or incompatible JSON configuration %s',
250
+ async (original) => {
251
+ const filePath = path.join(cwd, '.cursor/mcp.json');
252
+ await fixture(filePath, original);
253
+
254
+ await expect(prepareMcpConfig('cursor', options())).rejects.toThrow();
255
+ expect(await fs.readFile(filePath, 'utf8')).toBe(original);
256
+ }
257
+ );
258
+
259
+ it.each([
260
+ '[mcp_servers\n',
261
+ 'mcp_servers = "example"\n',
262
+ 'mcp_servers = { other = { url = "https://example.com/mcp" } }\n',
263
+ ])('rejects malformed or incompatible TOML configuration %s', async (original) => {
264
+ const filePath = path.join(cwd, '.codex/config.toml');
265
+ await fixture(filePath, original);
266
+
267
+ await expect(prepareMcpConfig('codex', options())).rejects.toThrow();
268
+ expect(await fs.readFile(filePath, 'utf8')).toBe(original);
269
+ });
270
+
271
+ it.each([0o640, 0o664])(
272
+ 'writes the prepared contents while preserving permissions %i',
273
+ async (mode) => {
274
+ const filePath = path.join(cwd, '.mcp.json');
275
+ await fixture(filePath, '{"theme":"dark"}\n');
276
+ await fs.chmod(filePath, mode);
277
+ const plan = await prepareMcpConfig('claude-code', options());
278
+
279
+ await writeMcpConfig(plan);
280
+
281
+ expect(await fs.readFile(filePath, 'utf8')).toBe(plan.contents);
282
+ if (process.platform !== 'win32') expect((await fs.stat(filePath)).mode & 0o777).toBe(mode);
283
+ const rerun = await prepareMcpConfig('claude-code', options());
284
+ expect(rerun.contents).toBeUndefined();
285
+ }
286
+ );
287
+
288
+ it.each([false, true])(
289
+ 'refuses configuration drift when an original file existed: %s',
290
+ async (existing) => {
291
+ const filePath = path.join(cwd, '.mcp.json');
292
+ if (existing) await fixture(filePath, '{}\n');
293
+ const plan = await prepareMcpConfig('claude-code', options());
294
+ const changed = '{"theme":"new-preference"}\n';
295
+ await fixture(filePath, changed);
296
+
297
+ await expect(writeMcpConfig(plan)).rejects.toThrow();
298
+ expect(await fs.readFile(filePath, 'utf8')).toBe(changed);
299
+ }
300
+ );
301
+
302
+ it('refuses to replace a configuration symlink or change its target', async () => {
303
+ const filePath = path.join(cwd, '.mcp.json');
304
+ const targetPath = path.join(directory, 'shared-config.json');
305
+ const original = '{"theme":"shared"}\n';
306
+ await fixture(targetPath, original);
307
+ const plan = await prepareMcpConfig('claude-code', options());
308
+ await fs.symlink(targetPath, filePath);
309
+
310
+ await expect(writeMcpConfig(plan)).rejects.toThrow();
311
+ expect((await fs.lstat(filePath)).isSymbolicLink()).toBe(true);
312
+ expect(await fs.readFile(targetPath, 'utf8')).toBe(original);
313
+ });
314
+ });
@@ -0,0 +1,207 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import fs from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { parse as parseToml } from 'smol-toml';
6
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
+
8
+ import { installSkills, setupAgent } from '../src/agent-setup.js';
9
+
10
+ let directory: string;
11
+ let argumentsFile: string;
12
+ let project: string;
13
+ const originalIsTTY = process.stdin.isTTY;
14
+
15
+ function executablePath(command: string): string {
16
+ const extension = process.platform === 'win32' ? '.cmd' : '';
17
+ return path.join(directory, `${command}${extension}`);
18
+ }
19
+
20
+ async function fakeExecutable(command: string, source: string) {
21
+ if (process.platform === 'win32') {
22
+ const script = path.join(directory, `${command}.cjs`);
23
+ await fs.writeFile(script, source);
24
+ await fs.writeFile(executablePath(command), `@"${process.execPath}" "${script}" %*\r\n`);
25
+ return;
26
+ }
27
+ await fs.writeFile(executablePath(command), `#!${process.execPath}\n${source}\n`, {
28
+ mode: 0o755,
29
+ });
30
+ }
31
+
32
+ beforeEach(async () => {
33
+ directory = await fs.mkdtemp(path.join(os.tmpdir(), 'mint-agent-setup-'));
34
+ argumentsFile = path.join(directory, 'arguments.json');
35
+ project = path.join(directory, 'project');
36
+ await fs.mkdir(project);
37
+ vi.stubEnv('PATH', directory);
38
+ vi.stubEnv('CODEX_HOME', '');
39
+ vi.stubEnv('CLAUDE_CONFIG_DIR', '');
40
+ vi.spyOn(process, 'cwd').mockReturnValue(project);
41
+ vi.spyOn(os, 'homedir').mockReturnValue(path.join(directory, 'home'));
42
+ process.stdin.isTTY = false;
43
+ await fakeExecutable(
44
+ 'npx',
45
+ `require('node:fs').writeFileSync(${JSON.stringify(argumentsFile)}, JSON.stringify(process.argv.slice(2)));`
46
+ );
47
+ });
48
+
49
+ afterEach(async () => {
50
+ vi.restoreAllMocks();
51
+ process.stdin.isTTY = originalIsTTY;
52
+ vi.unstubAllEnvs();
53
+ await fs.rm(directory, { recursive: true, force: true });
54
+ });
55
+
56
+ describe('agent setup skills installer', () => {
57
+ it('passes explicit agents and project scope without an interactive installer', async () => {
58
+ await installSkills(['claude-code', 'codex', 'cursor'], false);
59
+
60
+ expect(JSON.parse(await fs.readFile(argumentsFile, 'utf8'))).toEqual([
61
+ '--yes',
62
+ 'skills@1.7.4',
63
+ 'add',
64
+ 'https://mintlify.com/docs',
65
+ '--agent',
66
+ 'claude-code',
67
+ 'codex',
68
+ 'cursor',
69
+ '--yes',
70
+ ]);
71
+ });
72
+
73
+ it('forwards global scope to the skills installer', async () => {
74
+ await installSkills(['codex'], true);
75
+
76
+ expect(JSON.parse(await fs.readFile(argumentsFile, 'utf8'))).toContain('--global');
77
+ });
78
+
79
+ it('rejects a nonzero installer exit', async () => {
80
+ await fakeExecutable('npx', 'process.exit(1);');
81
+
82
+ await expect(installSkills(['codex'], false)).rejects.toThrow('Skills installation failed');
83
+ });
84
+
85
+ it('rejects partial installation failures even when the pinned installer exits zero', async () => {
86
+ await fakeExecutable('npx', "console.error('\\u001b[31mFailed to install 1\\u001b[0m');");
87
+
88
+ await expect(installSkills(['codex'], false)).rejects.toThrow('Skills installation failed');
89
+ });
90
+
91
+ it('rejects a missing npm runner', async () => {
92
+ await fs.unlink(executablePath('npx'));
93
+ const message =
94
+ process.platform === 'win32' ? 'Skills installation failed' : 'Could not run npx';
95
+
96
+ await expect(installSkills(['codex'], false)).rejects.toThrow(message);
97
+ });
98
+ });
99
+
100
+ describe('agent setup orchestration', () => {
101
+ it('passes a TOML URL override without embedded native argument quotes', async () => {
102
+ let output = '';
103
+ vi.spyOn(process.stdout, 'write').mockImplementation((chunk) => {
104
+ output += chunk.toString();
105
+ return true;
106
+ });
107
+ await fakeExecutable(
108
+ 'codex',
109
+ `require('node:fs').writeFileSync(${JSON.stringify(argumentsFile)}, JSON.stringify(process.argv.slice(2)));`
110
+ );
111
+
112
+ await setupAgent({ agents: ['codex'], global: false });
113
+ const command = output.match(/Codex: run (.+)\. Trust/)?.[1];
114
+ if (command === undefined) throw new Error('Missing Codex login command');
115
+
116
+ const result = spawnSync(command, { shell: true, env: process.env });
117
+ expect(result.status).toBe(0);
118
+ const args: unknown = JSON.parse(await fs.readFile(argumentsFile, 'utf8'));
119
+ if (!Array.isArray(args) || typeof args[1] !== 'string') {
120
+ throw new Error('Missing Codex configuration override');
121
+ }
122
+ expect(args[0]).toBe('-c');
123
+ expect(args[1]).not.toContain('"');
124
+ expect(args.slice(2)).toEqual(['mcp', 'login', 'mintlify-admin']);
125
+ expect(parseToml(args[1])).toEqual({
126
+ mcp_servers: { 'mintlify-admin': { url: 'https://mcp.mintlify.com' } },
127
+ });
128
+ });
129
+
130
+ it('preflights every target before installing skills or changing configuration', async () => {
131
+ await fs.mkdir(path.join(project, '.cursor'));
132
+ const conflict = '{"mcpServers":{"mintlify-admin":{"url":"https://example.com/mcp"}}}';
133
+ await fs.writeFile(path.join(project, '.cursor/mcp.json'), conflict);
134
+
135
+ await expect(setupAgent({ agents: ['codex', 'cursor'], global: false })).rejects.toThrow(
136
+ 'different configuration'
137
+ );
138
+ await expect(fs.readFile(argumentsFile)).rejects.toThrow();
139
+ await expect(fs.readFile(path.join(project, '.codex/config.toml'))).rejects.toThrow();
140
+ expect(await fs.readFile(path.join(project, '.cursor/mcp.json'), 'utf8')).toBe(conflict);
141
+ });
142
+
143
+ it('leaves MCP configuration untouched when skills installation fails', async () => {
144
+ await fakeExecutable('npx', 'process.exit(1);');
145
+
146
+ await expect(setupAgent({ agents: ['codex'], global: false })).rejects.toThrow();
147
+ await expect(fs.readFile(path.join(project, '.codex/config.toml'))).rejects.toThrow();
148
+ });
149
+
150
+ it('configures all selected agents after skills finish and deduplicates targets', async () => {
151
+ await setupAgent({
152
+ agents: ['codex', 'claude-code', 'cursor', 'codex'],
153
+ global: false,
154
+ });
155
+
156
+ const args: unknown = JSON.parse(await fs.readFile(argumentsFile, 'utf8'));
157
+ expect(args).toEqual([
158
+ '--yes',
159
+ 'skills@1.7.4',
160
+ 'add',
161
+ 'https://mintlify.com/docs',
162
+ '--agent',
163
+ 'codex',
164
+ 'claude-code',
165
+ 'cursor',
166
+ '--yes',
167
+ ]);
168
+ for (const file of ['.codex/config.toml', '.mcp.json', '.cursor/mcp.json']) {
169
+ expect(await fs.readFile(path.join(project, file), 'utf8')).toContain(
170
+ 'https://mcp.mintlify.com'
171
+ );
172
+ }
173
+ });
174
+
175
+ it('configures detected agents when running without a terminal', async () => {
176
+ vi.stubEnv('AI_AGENT', 'codex_cli');
177
+
178
+ await setupAgent({ global: false });
179
+
180
+ expect(JSON.parse(await fs.readFile(argumentsFile, 'utf8'))).toEqual([
181
+ '--yes',
182
+ 'skills@1.7.4',
183
+ 'add',
184
+ 'https://mintlify.com/docs',
185
+ '--agent',
186
+ 'codex',
187
+ '--yes',
188
+ ]);
189
+ expect(await fs.readFile(path.join(project, '.codex/config.toml'), 'utf8')).toContain(
190
+ 'https://mcp.mintlify.com'
191
+ );
192
+ });
193
+
194
+ it('requires agent selection when no supported agents are detected without a terminal', async () => {
195
+ vi.stubEnv('AI_AGENT', 'unknown-agent');
196
+
197
+ await expect(setupAgent({ global: false })).rejects.toThrow('Pass --agent');
198
+ await expect(fs.readFile(argumentsFile)).rejects.toThrow();
199
+ });
200
+
201
+ it('rejects unsupported agent names before spawning a command', async () => {
202
+ await expect(setupAgent({ agents: ['codex;echo unsafe'], global: false })).rejects.toThrow(
203
+ 'Unsupported agent'
204
+ );
205
+ await expect(fs.readFile(argumentsFile)).rejects.toThrow();
206
+ });
207
+ });