UNPKG

vibehub-cli

Version:

VibeHub CLI - Command line interface for VibeHub

99 lines 4.64 kB
import { Command } from 'commander'; import chalk from 'chalk'; import { VibeHubManager } from '../lib/vibehub-manager.js'; import { CloudService } from '../lib/cloud-service.js'; export const pullCommand = new Command('pull') .description('Pull updates from VibeHub cloud') .option('-f, --force', 'Force pull and overwrite local changes') .option('-d, --dry-run', 'Show what would be pulled without actually pulling') .option('-p, --project-id <id>', 'Project ID (if not in config)') .action(async (options) => { const cwd = process.cwd(); const vibehubManager = new VibeHubManager(cwd); try { const status = await vibehubManager.getStatus(); if (!status.initialized) { console.log(chalk.red('❌ Not a VibeHub repository')); console.log(chalk.blue('Run ') + chalk.cyan('vibe init') + chalk.blue(' to initialize a new repository')); return; } const config = status.config; if (!config.config?.autoSync) { console.log(chalk.yellow('⚠️ Auto-sync is disabled for this repository')); console.log(chalk.blue('Enable it in the config to use push/pull commands')); return; } // Get project ID const projectId = options.projectId || config.projectId; if (!projectId) { console.log(chalk.red('❌ Project ID not found')); console.log(chalk.blue('Please specify project ID with --project-id or update config')); return; } // Initialize cloud service using config const cloudConfig = config.cloud; if (!cloudConfig) { console.log(chalk.red('❌ Cloud configuration not found')); console.log(chalk.blue('Please run ') + chalk.cyan('vibe set <project-url>') + chalk.blue(' to connect to a cloud project')); return; } const cloudService = new CloudService({ apiUrl: cloudConfig.apiUrl, token: cloudConfig.token || process.env.VIBEHUB_TOKEN }); // Test connection const isConnected = await cloudService.testConnection(); if (!isConnected) { console.log(chalk.red('❌ Cannot connect to VibeHub cloud')); console.log(chalk.blue('Please check your API URL and authentication')); return; } console.log(chalk.blue('📥 Pulling from VibeHub cloud...\n')); // Get last sync time from local config const lastSync = config.lastSync; if (options.dryRun) { // Get sync status for dry run const syncStatus = await cloudService.getSyncStatus(projectId); console.log(chalk.blue('📋 Dry run - would pull:')); console.log(chalk.white(' Total commits: ') + chalk.cyan(syncStatus.totalCommits)); console.log(chalk.white(' Total sessions: ') + chalk.cyan(syncStatus.totalSessions)); console.log(chalk.white(' Last activity: ') + chalk.gray(syncStatus.lastActivity)); return; } // Pull from cloud const result = await cloudService.pull(projectId, lastSync, options.force); console.log(chalk.green('✅ Successfully pulled from VibeHub cloud!')); console.log(chalk.white(' New commits: ') + chalk.cyan(result.commits.length)); console.log(chalk.white(' New sessions: ') + chalk.cyan(result.sessions.length)); // Save pulled data locally if (result.commits.length > 0 || result.sessions.length > 0) { for (const commit of result.commits) { await vibehubManager.createCommit({ message: commit.message, author: commit.author, sessionId: commit.sessionId, files: commit.files || [], changes: commit.changes || {} }); } for (const session of result.sessions) { await vibehubManager.createSession({ prompt: session.prompt, response: session.response, files: session.files || [], metadata: session.metadata || {} }); } // Update last sync time await vibehubManager.updateConfig({ lastSync: result.lastSync }); console.log(chalk.blue(' Data saved locally')); } } catch (error) { console.error(chalk.red('Failed to pull from VibeHub cloud:'), error); process.exit(1); } }); //# sourceMappingURL=pull.js.map