vibehub-cli
Version:
VibeHub CLI - Command line interface for VibeHub
141 lines ⢠6.27 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import fs from 'fs-extra';
import path from 'path';
import { VibeHubManager } from '../lib/vibehub-manager.js';
export const addCommand = new Command('add')
.description('Add files to staging area for commit')
.argument('[files...]', 'Files to add (default: all files)')
.option('-A, --all', 'Add all files')
.option('-u, --update', 'Update already tracked files')
.action(async (files, options) => {
try {
console.log(chalk.blue('š Adding files to staging area...\n'));
// Check if we're in a VibeHub repository
const vibehubDir = path.join(process.cwd(), '.vibehub');
if (!await fs.pathExists(vibehubDir)) {
console.error(chalk.red('ā Not a VibeHub repository. Run "vibe init" first.'));
process.exit(1);
}
// Initialize VibeHub manager
const vibehubManager = new VibeHubManager(process.cwd());
// Determine which files to add
let filesToAdd = [];
if (options.all || files.length === 0) {
// Add all files in the current directory (excluding .vibehub)
const allFiles = await getAllFiles(process.cwd());
filesToAdd = allFiles.filter(file => !file.startsWith('.vibehub/'));
}
else {
// Add specific files
filesToAdd = files;
}
// Validate files exist
const existingFiles = [];
const missingFiles = [];
for (const file of filesToAdd) {
const filePath = path.resolve(file);
if (await fs.pathExists(filePath)) {
existingFiles.push(file);
}
else {
missingFiles.push(file);
}
}
if (missingFiles.length > 0) {
console.error(chalk.red('ā Some files not found:'));
missingFiles.forEach(file => console.error(chalk.red(` - ${file}`)));
process.exit(1);
}
// Add files to staging area
const stagingPath = path.join(vibehubDir, 'staging');
await fs.ensureDir(stagingPath);
const addedFiles = [];
for (const file of existingFiles) {
const filePath = path.resolve(file);
const relativePath = path.relative(process.cwd(), filePath);
const stagingFilePath = path.join(stagingPath, relativePath);
// Create directory structure in staging
await fs.ensureDir(path.dirname(stagingFilePath));
// Copy file to staging
await fs.copy(filePath, stagingFilePath);
addedFiles.push(relativePath);
}
// Save staging information
const stagingInfo = {
files: addedFiles,
timestamp: new Date().toISOString(),
totalFiles: addedFiles.length
};
await fs.writeJson(path.join(stagingPath, 'staging.json'), stagingInfo, { spaces: 2 });
// Sync prompts and generations from Cursor workspace
console.log(chalk.blue('\nš Syncing Cursor workspace data...'));
try {
const config = await vibehubManager.getConfig();
const workspaceId = config.workspace?.cursorWorkspaceId;
if (workspaceId) {
await vibehubManager.syncWorkspace(workspaceId);
// Verify CSV file was created/updated successfully
const csvPath = path.join(vibehubDir, 'workspace', 'exports', `workspace-${workspaceId}`, 'prompts_with_timestamps.csv');
if (await fs.pathExists(csvPath)) {
const csvContent = await fs.readFile(csvPath, 'utf-8');
const lines = csvContent.split('\n').filter(line => line.trim());
if (lines.length > 1) { // Has header + at least one data row
const promptCount = lines.length - 1; // Subtract header line
console.log(chalk.green(`ā
Cursor workspace synced successfully`));
console.log(chalk.blue(`š CSV file verified: ${promptCount} prompts extracted`));
}
else {
console.log(chalk.yellow('ā ļø CSV file exists but is empty'));
}
}
else {
console.log(chalk.yellow('ā ļø CSV file not found after sync'));
}
}
else {
console.log(chalk.yellow('ā ļø No Cursor workspace found to sync'));
}
}
catch (syncError) {
console.log(chalk.yellow('ā ļø Could not sync Cursor workspace:', syncError instanceof Error ? syncError.message : 'Unknown error'));
}
// Display results
console.log(chalk.green(`\nā
Added ${addedFiles.length} file(s) to staging area:`));
addedFiles.forEach(file => {
console.log(chalk.gray(` + ${file}`));
});
console.log(chalk.blue('\nš” Next steps:'));
console.log(chalk.gray(' vibe commit -m "your commit message"'));
console.log(chalk.gray(' vibe push'));
}
catch (error) {
console.error(chalk.red('ā Failed to add files:'), error instanceof Error ? error.message : 'Unknown error');
process.exit(1);
}
});
// Helper function to get all files in a directory recursively
async function getAllFiles(dir, baseDir = dir) {
const files = [];
const items = await fs.readdir(dir);
for (const item of items) {
const fullPath = path.join(dir, item);
const relativePath = path.relative(baseDir, fullPath);
const stat = await fs.stat(fullPath);
if (stat.isDirectory()) {
// Skip .vibehub directory
if (item === '.vibehub')
continue;
// Skip node_modules and other common ignore directories
if (['node_modules', '.git', '.DS_Store'].includes(item))
continue;
const subFiles = await getAllFiles(fullPath, baseDir);
files.push(...subFiles);
}
else {
files.push(relativePath);
}
}
return files;
}
//# sourceMappingURL=add.js.map