@vespermcp/mcp-server 1.2.20 → 1.2.22

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 (38) hide show
  1. package/README.md +49 -0
  2. package/build/cloud/adapters/supabase.js +49 -0
  3. package/build/cloud/storage-manager.js +6 -0
  4. package/build/export/exporter.js +22 -9
  5. package/build/gateway/unified-dataset-gateway.js +410 -0
  6. package/build/index.js +1592 -837
  7. package/build/ingestion/hf-downloader.js +12 -2
  8. package/build/ingestion/ingestor.js +19 -9
  9. package/build/install/install-service.js +11 -6
  10. package/build/lib/supabase.js +3 -0
  11. package/build/metadata/scraper.js +85 -14
  12. package/build/python/asset_downloader_engine.py +22 -1
  13. package/build/python/convert_engine.py +92 -0
  14. package/build/python/export_engine.py +45 -0
  15. package/build/python/hf_fallback.py +196 -45
  16. package/build/python/kaggle_engine.py +77 -5
  17. package/build/python/normalize_engine.py +83 -0
  18. package/build/python/vesper/core/asset_downloader.py +238 -48
  19. package/build/search/engine.js +43 -5
  20. package/build/search/jit-orchestrator.js +18 -14
  21. package/build/search/query-intent.js +509 -0
  22. package/build/tools/formatter.js +6 -3
  23. package/build/utils/python-runtime.js +130 -0
  24. package/package.json +7 -5
  25. package/scripts/postinstall.cjs +87 -31
  26. package/scripts/wizard.cjs +601 -0
  27. package/scripts/wizard.js +306 -12
  28. package/src/python/__pycache__/config.cpython-312.pyc +0 -0
  29. package/src/python/__pycache__/kaggle_engine.cpython-312.pyc +0 -0
  30. package/src/python/asset_downloader_engine.py +22 -1
  31. package/src/python/convert_engine.py +92 -0
  32. package/src/python/export_engine.py +45 -0
  33. package/src/python/hf_fallback.py +196 -45
  34. package/src/python/kaggle_engine.py +77 -5
  35. package/src/python/normalize_engine.py +83 -0
  36. package/src/python/requirements.txt +12 -0
  37. package/src/python/vesper/core/asset_downloader.py +238 -48
  38. package/wizard.cjs +3 -0
@@ -0,0 +1,601 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ─────────────────────────────────────────────────────────────
4
+ // vesper-wizard — Zero-friction local setup for Vesper MCP
5
+ // Run: npx vesper-wizard@latest
6
+ // ─────────────────────────────────────────────────────────────
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const os = require('os');
11
+ const crypto = require('crypto');
12
+ const { execSync, spawnSync } = require('child_process');
13
+ const http = require('http');
14
+ const https = require('https');
15
+ const readline = require('readline');
16
+
17
+ // ── Paths ────────────────────────────────────────────────────
18
+ const HOME = os.homedir();
19
+ const VESPER_DIR = path.join(HOME, '.vesper');
20
+ const CONFIG_TOML = path.join(VESPER_DIR, 'config.toml');
21
+ const DATA_DIR = path.join(VESPER_DIR, 'data');
22
+ const IS_WIN = process.platform === 'win32';
23
+ const APPDATA = process.env.APPDATA || path.join(HOME, 'AppData', 'Roaming');
24
+
25
+ // ── Helpers ──────────────────────────────────────────────────
26
+ function ensureDir(dir) {
27
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
28
+ }
29
+
30
+ function generateLocalKey() {
31
+ const random = crypto.randomBytes(24).toString('hex');
32
+ return `vesper_sk_local_${random}`;
33
+ }
34
+
35
+ function readToml(filePath) {
36
+ if (!fs.existsSync(filePath)) return {};
37
+ const content = fs.readFileSync(filePath, 'utf8');
38
+ const obj = {};
39
+ for (const line of content.split('\n')) {
40
+ const m = line.match(/^\s*(\w+)\s*=\s*"(.*)"\s*$/);
41
+ if (m) obj[m[1]] = m[2];
42
+ }
43
+ return obj;
44
+ }
45
+
46
+ function writeToml(filePath, data) {
47
+ ensureDir(path.dirname(filePath));
48
+ const lines = Object.entries(data).map(([k, v]) => `${k} = "${v}"`);
49
+ fs.writeFileSync(filePath, lines.join('\n') + '\n', 'utf8');
50
+ }
51
+
52
+ function dim(text) { return `\x1b[2m${text}\x1b[0m`; }
53
+ function bold(text) { return `\x1b[1m${text}\x1b[0m`; }
54
+ function green(text) { return `\x1b[32m${text}\x1b[0m`; }
55
+ function cyan(text) { return `\x1b[36m${text}\x1b[0m`; }
56
+ function yellow(text) { return `\x1b[33m${text}\x1b[0m`; }
57
+ function red(text) { return `\x1b[31m${text}\x1b[0m`; }
58
+ function magenta(text) { return `\x1b[35m${text}\x1b[0m`; }
59
+
60
+ // ── Vesper API URL resolution ────────────────────────────────
61
+ const VESPER_API_URL = process.env.VESPER_API_URL || '';
62
+ const DEFAULT_VESPER_API_CANDIDATES = [
63
+ 'https://getvesper.dev',
64
+ 'http://localhost:3000',
65
+ 'http://127.0.0.1:3000',
66
+ ];
67
+
68
+ // ── Device Auth Helpers ──────────────────────────────────────
69
+ function httpJson(method, url, body) {
70
+ return new Promise((resolve, reject) => {
71
+ const parsed = new URL(url);
72
+ const lib = parsed.protocol === 'https:' ? https : http;
73
+ const opts = {
74
+ method,
75
+ hostname: parsed.hostname,
76
+ port: parsed.port || (parsed.protocol === 'https:' ? 443 : 80),
77
+ path: parsed.pathname + parsed.search,
78
+ headers: { 'Content-Type': 'application/json' },
79
+ };
80
+ const req = lib.request(opts, (res) => {
81
+ let data = '';
82
+ res.on('data', (chunk) => (data += chunk));
83
+ res.on('end', () => {
84
+ try { resolve({ status: res.statusCode, body: JSON.parse(data) }); }
85
+ catch { resolve({ status: res.statusCode, body: data }); }
86
+ });
87
+ });
88
+ req.on('error', reject);
89
+ if (body) req.write(JSON.stringify(body));
90
+ req.end();
91
+ });
92
+ }
93
+
94
+ async function probeDeviceAuth(baseUrl) {
95
+ try {
96
+ const res = await httpJson('POST', `${baseUrl}/api/auth/device/start`);
97
+ if (res.status === 201 && !!res.body && !!res.body.code) {
98
+ return { baseUrl, status: 'ready', response: res.body };
99
+ }
100
+
101
+ if (res.status === 503 && res.body && res.body.requiresSetup) {
102
+ return {
103
+ baseUrl,
104
+ status: 'setup-required',
105
+ response: res.body,
106
+ message: res.body.error || 'Auth storage is not initialized.',
107
+ };
108
+ }
109
+
110
+ return {
111
+ baseUrl,
112
+ status: 'unreachable',
113
+ response: res.body,
114
+ message: typeof res.body === 'string' ? res.body : JSON.stringify(res.body),
115
+ };
116
+ } catch (error) {
117
+ return {
118
+ baseUrl,
119
+ status: 'unreachable',
120
+ message: error && error.message ? error.message : 'Request failed',
121
+ };
122
+ }
123
+ }
124
+
125
+ async function resolveVesperApiBaseUrl() {
126
+ const candidates = VESPER_API_URL
127
+ ? [VESPER_API_URL]
128
+ : DEFAULT_VESPER_API_CANDIDATES;
129
+
130
+ let setupRequiredProbe = null;
131
+
132
+ for (const candidate of candidates) {
133
+ const probe = await probeDeviceAuth(candidate);
134
+ if (probe.status === 'ready') {
135
+ return probe;
136
+ }
137
+
138
+ if (!setupRequiredProbe && probe.status === 'setup-required') {
139
+ setupRequiredProbe = probe;
140
+ }
141
+ }
142
+
143
+ return setupRequiredProbe;
144
+ }
145
+
146
+ function openBrowser(url) {
147
+ try {
148
+ if (process.platform === 'win32') {
149
+ spawnSync('cmd', ['/c', 'start', '', url], { stdio: 'ignore' });
150
+ } else if (process.platform === 'darwin') {
151
+ spawnSync('open', [url], { stdio: 'ignore' });
152
+ } else {
153
+ spawnSync('xdg-open', [url], { stdio: 'ignore' });
154
+ }
155
+ } catch { /* browser open is best-effort */ }
156
+ }
157
+
158
+ function askYesNo(question) {
159
+ return new Promise((resolve) => {
160
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
161
+ rl.question(` ${question} ${dim('[Y/n]')} `, (answer) => {
162
+ rl.close();
163
+ resolve(!answer || answer.toLowerCase().startsWith('y'));
164
+ });
165
+ });
166
+ }
167
+
168
+ function askInput(question) {
169
+ return new Promise((resolve) => {
170
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
171
+ rl.question(` ${question} `, (answer) => {
172
+ rl.close();
173
+ resolve(String(answer || '').trim());
174
+ });
175
+ });
176
+ }
177
+
178
+ async function askChoice(question, choices, defaultValue) {
179
+ console.log(` ${question}`);
180
+ choices.forEach((choice, index) => {
181
+ console.log(` ${dim(String(index + 1) + ')')} ${choice.label}`);
182
+ });
183
+
184
+ const prompt = defaultValue ? `${dim('[default: ' + defaultValue + ']')}` : '';
185
+ const answer = await askInput(`${prompt} ${cyan('→')} Choose an option:`);
186
+ if (!answer && defaultValue) {
187
+ return defaultValue;
188
+ }
189
+
190
+ const numeric = Number(answer);
191
+ if (Number.isFinite(numeric) && numeric >= 1 && numeric <= choices.length) {
192
+ return choices[numeric - 1].value;
193
+ }
194
+
195
+ const matched = choices.find((choice) => choice.value === answer);
196
+ return matched ? matched.value : defaultValue;
197
+ }
198
+
199
+ function isCloudApiKey(value) {
200
+ return !!value && value.startsWith('vesper_sk_') && !value.startsWith('vesper_sk_local_');
201
+ }
202
+
203
+ async function promptForManualApiKey() {
204
+ console.log(`\n ${cyan('■')} ${bold('Manual API Key')}`);
205
+ console.log(` ${dim('Paste a Vesper cloud API key. It will be stored locally in config.toml.\n')}`);
206
+
207
+ while (true) {
208
+ const value = await askInput(`${cyan('→')} Vesper API key:`);
209
+ if (isCloudApiKey(value)) {
210
+ return value;
211
+ }
212
+ console.log(` ${yellow('!')} ${yellow('Expected a Vesper key starting with vesper_sk_')}`);
213
+ }
214
+ }
215
+
216
+ async function chooseAuthMode(existingKey, existingAuthMode) {
217
+ const hasExistingKey = !!existingKey;
218
+ if (hasExistingKey) {
219
+ console.log(` ${dim('Current key:')} ${dim(existingKey.slice(0, 24) + '...')}`);
220
+ console.log(` ${dim('Current mode:')} ${dim(existingAuthMode || (isCloudApiKey(existingKey) ? 'cloud' : 'local_unified'))}`);
221
+ }
222
+
223
+ const choices = [];
224
+ choices.push({ value: 'browser', label: 'Sign in through the browser' });
225
+ choices.push({ value: 'manual', label: 'Provide Vesper API key manually' });
226
+
227
+ return await askChoice(`${cyan('→')} How do you want to authenticate Vesper?`, choices, 'browser');
228
+ }
229
+
230
+ async function deviceAuthFlow() {
231
+ console.log(`\n ${cyan('■')} ${bold('Device Authentication')}`);
232
+ console.log(` ${dim('Link your CLI to a Vesper account for cloud features\n')}`);
233
+
234
+ const resolvedApiBaseUrl = await resolveVesperApiBaseUrl();
235
+ if (!resolvedApiBaseUrl) {
236
+ console.log(` ${red('✗')} ${red('Could not reach any Vesper auth endpoint.')}`);
237
+ console.log(` ${dim('Tried:')} ${dim((VESPER_API_URL ? [VESPER_API_URL] : DEFAULT_VESPER_API_CANDIDATES).join(', '))}`);
238
+ console.log(` ${dim('If your landing app is running locally, start it on http://localhost:3000 or set VESPER_API_URL.')}`);
239
+ console.log(` ${dim('Falling back to manual key entry.\n')}`);
240
+ return null;
241
+ }
242
+
243
+ if (resolvedApiBaseUrl.status === 'setup-required') {
244
+ console.log(` ${yellow('!')} ${yellow('Reached Vesper auth endpoint, but local auth storage is not initialized.')}`);
245
+ console.log(` ${dim('Endpoint:')} ${dim(resolvedApiBaseUrl.baseUrl)}`);
246
+ console.log(` ${dim('Reason:')} ${dim(resolvedApiBaseUrl.message || 'Apply Supabase migrations first.')}`);
247
+ console.log(` ${dim('Run the SQL in supabase/migrations/001_device_auth.sql and 002_rate_limits.sql, then retry.')}`);
248
+ console.log(` ${dim('Falling back to manual key entry.\n')}`);
249
+ return null;
250
+ }
251
+
252
+ console.log(` ${dim('Auth endpoint:')} ${dim(resolvedApiBaseUrl.baseUrl)}\n`);
253
+
254
+ // Step 1: Call /api/auth/device/start
255
+ process.stdout.write(` ${dim('Requesting device code...')}`);
256
+ let startRes;
257
+ try {
258
+ startRes = await httpJson('POST', `${resolvedApiBaseUrl.baseUrl}/api/auth/device/start`);
259
+ } catch (err) {
260
+ console.log(` ${red('✗')}`);
261
+ console.log(` ${red('Could not reach Vesper API at')} ${dim(resolvedApiBaseUrl.baseUrl)}`);
262
+ console.log(` ${dim('Falling back to manual key entry.\n')}`);
263
+ return null;
264
+ }
265
+
266
+ if (startRes.status !== 201 || !startRes.body.code) {
267
+ console.log(` ${red('✗')}`);
268
+ console.log(` ${red('Unexpected response:')} ${dim(JSON.stringify(startRes.body))}`);
269
+ return null;
270
+ }
271
+
272
+ const { code, loginUrl } = startRes.body;
273
+ console.log(` ${green('✓')}\n`);
274
+
275
+ // Step 2: Display code and open browser
276
+ console.log(` ┌───────────────────────────────────────────────┐`);
277
+ console.log(` │ │`);
278
+ console.log(` │ ${bold('Your device code:')} ${cyan(bold(code))} │`);
279
+ console.log(` │ │`);
280
+ console.log(` │ ${dim('Open this URL to sign in:')} │`);
281
+ console.log(` │ ${cyan(loginUrl.padEnd(41))}│`);
282
+ console.log(` │ │`);
283
+ console.log(` └───────────────────────────────────────────────┘\n`);
284
+
285
+ openBrowser(loginUrl);
286
+ console.log(` ${dim('Browser opened automatically.')}`);
287
+ console.log(` ${dim('Waiting for you to sign in...')}\n`);
288
+
289
+ // Step 3: Poll until confirmed or expired
290
+ const POLL_INTERVAL = 3000; // 3 seconds
291
+ const MAX_POLLS = 200; // 10 min max (200 × 3s)
292
+ let polls = 0;
293
+ const spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
294
+
295
+ while (polls < MAX_POLLS) {
296
+ polls++;
297
+ const frame = spinner[polls % spinner.length];
298
+ process.stdout.write(`\r ${cyan(frame)} Polling... (${polls})`);
299
+
300
+ try {
301
+ const pollRes = await httpJson('GET', `${resolvedApiBaseUrl.baseUrl}/api/auth/device/poll?code=${code}`);
302
+
303
+ if (pollRes.body.status === 'confirmed' && pollRes.body.apiKey) {
304
+ process.stdout.write(`\r ${green('✓')} Device authenticated! \n`);
305
+ console.log(` ${dim('Email:')} ${pollRes.body.email || 'linked'}`);
306
+ return pollRes.body.apiKey;
307
+ }
308
+
309
+ if (pollRes.body.status === 'expired') {
310
+ process.stdout.write(`\r ${red('✗')} Device code expired. \n`);
311
+ console.log(` ${dim('Run the wizard again to get a new code.')}`);
312
+ return null;
313
+ }
314
+ } catch {
315
+ // Network hiccup — keep polling
316
+ }
317
+
318
+ await new Promise((r) => setTimeout(r, POLL_INTERVAL));
319
+ }
320
+
321
+ process.stdout.write(`\r ${red('✗')} Timed out waiting for authentication.\n`);
322
+ return null;
323
+ }
324
+
325
+ function printBanner() {
326
+ console.log(`
327
+ ${dim('─────────────────────────────────────────────────')}
328
+
329
+ ${bold('██ ██ ███████ ███████ ██████ ███████ ██████')}
330
+ ${bold('██ ██ ██ ██ ██ ██ ██ ██ ██')}
331
+ ${bold('██ ██ █████ ███████ ██████ █████ ██████')}
332
+ ${bold(' ██ ██ ██ ██ ██ ██ ██ ██')}
333
+ ${bold(' ████ ███████ ███████ ██ ███████ ██ ██')}
334
+
335
+ ${cyan('dataset intelligence layer')}
336
+ ${dim('local-first • zero-config • agent-native')}
337
+
338
+ ${dim('─────────────────────────────────────────────────')}
339
+ `);
340
+ }
341
+
342
+ // ── MCP Auto-Config ──────────────────────────────────────────
343
+ function getAllAgentConfigs() {
344
+ const isMac = process.platform === 'darwin';
345
+ return [
346
+ {
347
+ name: 'Claude Code',
348
+ path: path.join(HOME, '.claude.json'),
349
+ format: 'mcpServers',
350
+ },
351
+ {
352
+ name: 'Claude Desktop',
353
+ path: IS_WIN
354
+ ? path.join(APPDATA, 'Claude', 'claude_desktop_config.json')
355
+ : isMac
356
+ ? path.join(HOME, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json')
357
+ : path.join(HOME, '.config', 'claude', 'claude_desktop_config.json'),
358
+ format: 'mcpServers',
359
+ },
360
+ {
361
+ name: 'Cursor',
362
+ path: path.join(HOME, '.cursor', 'mcp.json'),
363
+ format: 'mcpServers',
364
+ },
365
+ {
366
+ name: 'VS Code',
367
+ path: IS_WIN
368
+ ? path.join(APPDATA, 'Code', 'User', 'mcp.json')
369
+ : isMac
370
+ ? path.join(HOME, 'Library', 'Application Support', 'Code', 'User', 'mcp.json')
371
+ : path.join(HOME, '.config', 'Code', 'User', 'mcp.json'),
372
+ format: 'servers',
373
+ },
374
+ {
375
+ name: 'Codex',
376
+ path: path.join(HOME, '.codex', 'config.toml'),
377
+ format: 'toml',
378
+ },
379
+ {
380
+ name: 'Gemini CLI',
381
+ path: path.join(HOME, '.gemini', 'settings.json'),
382
+ format: 'mcpServers',
383
+ },
384
+ ];
385
+ }
386
+
387
+ function installMcpToAgent(agent) {
388
+ const npxCmd = IS_WIN ? 'npx.cmd' : 'npx';
389
+ const serverEntry = { command: npxCmd, args: ['-y', '@vespermcp/mcp-server@latest'] };
390
+
391
+ try {
392
+ if (agent.format === 'toml') {
393
+ let content = fs.existsSync(agent.path) ? fs.readFileSync(agent.path, 'utf8') : '';
394
+ if (content.includes('[mcp_servers.vesper]')) return true;
395
+ ensureDir(path.dirname(agent.path));
396
+ content += `\n[mcp_servers.vesper]\ncommand = "${serverEntry.command}"\nargs = [${serverEntry.args.map(a => `"${a}"`).join(', ')}]\n`;
397
+ fs.writeFileSync(agent.path, content, 'utf8');
398
+ return true;
399
+ }
400
+
401
+ let config = {};
402
+ if (fs.existsSync(agent.path)) {
403
+ try { config = JSON.parse(fs.readFileSync(agent.path, 'utf8').trim() || '{}'); } catch { config = {}; }
404
+ } else {
405
+ ensureDir(path.dirname(agent.path));
406
+ }
407
+
408
+ const key = agent.format === 'servers' ? 'servers' : 'mcpServers';
409
+ if (!config[key]) config[key] = {};
410
+
411
+ const entry = agent.format === 'servers'
412
+ ? { type: 'stdio', ...serverEntry }
413
+ : serverEntry;
414
+
415
+ config[key].vesper = entry;
416
+ fs.writeFileSync(agent.path, JSON.stringify(config, null, 2), 'utf8');
417
+ return true;
418
+ } catch {
419
+ return false;
420
+ }
421
+ }
422
+
423
+ // ── Server Health Check ──────────────────────────────────────
424
+ async function checkServerHealth() {
425
+ try {
426
+ // Quick stdio check — spawn server and see if it responds
427
+ const result = spawnSync(IS_WIN ? 'npx.cmd' : 'npx', ['-y', '@vespermcp/mcp-server@latest', '--version'], {
428
+ timeout: 10000,
429
+ encoding: 'utf8',
430
+ stdio: ['pipe', 'pipe', 'pipe'],
431
+ });
432
+ return result.status === 0 || (result.stderr && result.stderr.includes('Vesper'));
433
+ } catch {
434
+ return false;
435
+ }
436
+ }
437
+
438
+ // ── Main Wizard ──────────────────────────────────────────────
439
+ async function main() {
440
+ printBanner();
441
+
442
+ console.log(` ${green('→')} Setting up Vesper on ${bold(os.hostname())}\n`);
443
+
444
+ // ─── Step 1: Create directories ────────────────────────────
445
+ process.stdout.write(` ${dim('[')}${cyan('1/6')}${dim(']')} Creating local directories...`);
446
+ ensureDir(VESPER_DIR);
447
+ ensureDir(DATA_DIR);
448
+ ensureDir(path.join(DATA_DIR, 'raw'));
449
+ ensureDir(path.join(DATA_DIR, 'processed'));
450
+ ensureDir(path.join(VESPER_DIR, 'datasets'));
451
+ console.log(` ${green('✓')}`);
452
+
453
+ // ─── Step 2: Authenticate (device flow or local key) ──────
454
+ console.log(`\n ${dim('[')}${cyan('2/6')}${dim(']')} Authentication`);
455
+
456
+ const existing = readToml(CONFIG_TOML);
457
+ let localKey = existing.api_key || '';
458
+ let authMode = existing.auth_mode || '';
459
+
460
+ const authChoice = await chooseAuthMode(localKey, authMode);
461
+
462
+ if (authChoice === 'manual') {
463
+ localKey = await promptForManualApiKey();
464
+ authMode = 'cloud';
465
+ console.log(` ${green('✓')} Cloud API key saved from manual input`);
466
+ } else if (authChoice === 'browser') {
467
+ const cloudKey = await deviceAuthFlow();
468
+ if (cloudKey) {
469
+ localKey = cloudKey;
470
+ authMode = 'cloud';
471
+ } else {
472
+ console.log(`\n ${yellow('!')} Browser sign-in did not complete. Falling back to manual key entry.`);
473
+ localKey = await promptForManualApiKey();
474
+ authMode = 'cloud';
475
+ }
476
+ }
477
+
478
+ const configData = { ...existing, api_key: localKey, auth_mode: authMode };
479
+ writeToml(CONFIG_TOML, configData);
480
+ console.log(` ${dim('Key:')} ${dim(localKey.slice(0, 24) + '...')} ${dim('→')} ${dim(CONFIG_TOML)}`);
481
+
482
+ // ─── Step 3: Local vault initialization ────────────────────
483
+ process.stdout.write(`\n ${dim('[')}${cyan('3/6')}${dim(']')} Initializing local credentials vault...`);
484
+ const vaultData = readToml(CONFIG_TOML);
485
+ if (!vaultData.auth_mode) vaultData.auth_mode = 'local_unified';
486
+ writeToml(CONFIG_TOML, vaultData);
487
+ console.log(` ${green('✓')}`);
488
+ console.log(` ${dim('Mode:')} ${dim(vaultData.auth_mode === 'cloud' ? 'cloud (linked to Vesper account)' : 'single local Vesper key (no external keys required)')}`);
489
+
490
+ // ─── Step 4: Install @vespermcp/mcp-server ─────────────────
491
+ console.log(`\n ${dim('[')}${cyan('4/6')}${dim(']')} Installing Vesper MCP server...`);
492
+ try {
493
+ const npmCmd = IS_WIN ? 'npx.cmd' : 'npx';
494
+ spawnSync(npmCmd, ['-y', '@vespermcp/mcp-server@latest', '--setup', '--silent'], {
495
+ stdio: 'inherit',
496
+ timeout: 120000,
497
+ });
498
+ console.log(` ${green('✓')} @vespermcp/mcp-server installed`);
499
+ } catch {
500
+ console.log(` ${yellow('⚠')} Could not auto-install — run manually: npx -y @vespermcp/mcp-server@latest --setup`);
501
+ }
502
+
503
+ // ─── Step 5: Auto-configure all detected IDEs ──────────────
504
+ process.stdout.write(`\n ${dim('[')}${cyan('5/6')}${dim(']')} Configuring coding agents...`);
505
+ const agents = getAllAgentConfigs();
506
+ const configuredAgents = [];
507
+ const skippedAgents = [];
508
+
509
+ for (const agent of agents) {
510
+ const dirExists = fs.existsSync(path.dirname(agent.path));
511
+ const fileExists = fs.existsSync(agent.path);
512
+ if (fileExists || dirExists) {
513
+ const ok = installMcpToAgent(agent);
514
+ if (ok) configuredAgents.push(agent.name);
515
+ else skippedAgents.push(agent.name);
516
+ }
517
+ }
518
+ console.log(` ${green('✓')}`);
519
+
520
+ if (configuredAgents.length > 0) {
521
+ console.log(`\n ┌───────────────────────────────────────────────┐`);
522
+ console.log(` │ ${bold('MCP Auto-Configured')} │`);
523
+ console.log(` ├───────────────────────────────────────────────┤`);
524
+ for (const name of configuredAgents) {
525
+ console.log(` │ ${green('✓')} ${name.padEnd(42)}│`);
526
+ }
527
+ console.log(` └───────────────────────────────────────────────┘`);
528
+ }
529
+
530
+ // ─── Step 6: Verify ────────────────────────────────────────
531
+ console.log(`\n ${dim('[')}${cyan('6/6')}${dim(']')} Verifying installation...`);
532
+
533
+ const dbExists = fs.existsSync(path.join(DATA_DIR, 'metadata.db'));
534
+ const vecExists = fs.existsSync(path.join(DATA_DIR, 'vectors.json')) || fs.existsSync(path.join(DATA_DIR, 'vectors.bin'));
535
+ const keyStored = fs.existsSync(CONFIG_TOML);
536
+
537
+ console.log(` ${keyStored ? green('✓') : red('✗')} Local API key ${dim(CONFIG_TOML)}`);
538
+ console.log(` ${dbExists ? green('✓') : yellow('⚠')} Dataset index ${dim(dbExists ? 'ready' : 'will build on first search')}`);
539
+ console.log(` ${vecExists ? green('✓') : yellow('⚠')} Vector store ${dim(vecExists ? 'ready' : 'will build on first search')}`);
540
+ console.log(` ${configuredAgents.length > 0 ? green('✓') : yellow('⚠')} MCP agents ${dim(configuredAgents.length + ' configured')}`);
541
+
542
+ // ─── Final Summary ─────────────────────────────────────────
543
+ const finalConfig = readToml(CONFIG_TOML);
544
+ const isCloud = finalConfig.auth_mode === 'cloud';
545
+ console.log(`
546
+ ${dim('═════════════════════════════════════════════════')}
547
+
548
+ ${green(bold('✓ Vesper is ready!'))}
549
+
550
+ ${bold(isCloud ? 'Your cloud API key:' : 'Your local API key:')}
551
+ ${cyan(finalConfig.api_key || localKey)}
552
+
553
+ ${bold('Auth mode:')}
554
+ ${dim(isCloud ? '☁ Cloud (linked to Vesper account)' : '🔑 Local-only (key never leaves your machine)')}
555
+
556
+ ${bold('Config file:')}
557
+ ${dim(CONFIG_TOML)}
558
+
559
+ ${bold('What just happened:')}
560
+ ${dim('1.')} ${isCloud ? 'Linked to your Vesper cloud account' : 'Generated a local API key (never leaves your machine)'}
561
+ ${dim('2.')} Initialized local credentials vault
562
+ ${dim('3.')} Auto-configured MCP for ${configuredAgents.length > 0 ? configuredAgents.join(', ') : 'detected agents'}
563
+ ${dim('4.')} Vesper server ready on stdio transport
564
+
565
+ ${dim('─────────────────────────────────────────────────')}
566
+
567
+ ${bold('Quick start — try in your AI assistant:')}
568
+
569
+ ${cyan('Search datasets')}
570
+ ${dim('>')} vesper_search(query="sentiment analysis")
571
+
572
+ ${cyan('Download & prepare')}
573
+ ${dim('>')} prepare_dataset(query="image classification cats dogs")
574
+
575
+ ${cyan('Quality analysis')}
576
+ ${dim('>')} analyze_quality(dataset_id="imdb")
577
+
578
+ ${cyan('Export to your project')}
579
+ ${dim('>')} export_dataset(dataset_id="imdb", format="parquet")
580
+
581
+ ${dim('─────────────────────────────────────────────────')}
582
+
583
+ ${bold('Unified API — one interface, every source:')}
584
+ HuggingFace · Kaggle · OpenML · data.world
585
+
586
+ ${dim('Agents call localhost Vesper APIs with one local key.')}
587
+ ${dim('Vesper adapters handle provider routing internally.')}
588
+
589
+ ${dim('─────────────────────────────────────────────────')}
590
+
591
+ ${yellow('→')} Restart your IDE to activate MCP
592
+ ${dim('Docs:')} https://github.com/vesper/mcp-server
593
+
594
+ ${dim('═════════════════════════════════════════════════')}
595
+ `);
596
+ }
597
+
598
+ main().catch((err) => {
599
+ console.error(`\n${red('Error:')} ${err.message || err}`);
600
+ process.exit(1);
601
+ });