vibehub-cli
Version:
VibeHub CLI - Command line interface for VibeHub
179 lines ⢠6.94 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { VibeHubManager } from '../lib/vibehub-manager.js';
export const sessionCommand = new Command('session')
.description('Manage AI sessions and link them to commits')
.option('-c, --create', 'Create a new AI session')
.option('-l, --list', 'List all sessions')
.option('-s, --show <sessionId>', 'Show session details')
.option('-d, --delete <sessionId>', 'Delete a session')
.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;
}
if (options.create) {
await createSession(vibehubManager);
}
else if (options.list) {
await listSessions(vibehubManager);
}
else if (options.show) {
await showSession(vibehubManager, options.show);
}
else if (options.delete) {
await deleteSession(vibehubManager, options.delete);
}
else {
// Default: interactive mode
await interactiveSession(vibehubManager);
}
}
catch (error) {
console.error(chalk.red('Session operation failed:'), error);
}
});
async function createSession(vibehubManager) {
console.log(chalk.blue('š¤ Creating new AI session...\n'));
const answers = await inquirer.prompt([
{
type: 'input',
name: 'prompt',
message: 'What did you ask the AI?',
validate: (input) => {
if (!input.trim()) {
return 'Prompt cannot be empty';
}
return true;
}
},
{
type: 'editor',
name: 'response',
message: 'What was the AI response? (opens in editor)',
validate: (input) => {
if (!input.trim()) {
return 'Response cannot be empty';
}
return true;
}
},
{
type: 'input',
name: 'files',
message: 'Which files were affected? (comma-separated)',
default: ''
},
{
type: 'input',
name: 'metadata',
message: 'Additional metadata (JSON format, optional):',
default: '{}'
}
]);
try {
const sessionId = await vibehubManager.createSession({
prompt: answers.prompt.trim(),
response: answers.response.trim(),
files: answers.files ? answers.files.split(',').map((f) => f.trim()).filter((f) => f) : [],
metadata: JSON.parse(answers.metadata || '{}')
});
console.log(chalk.green('\nā
AI session created successfully!'));
console.log(chalk.white('Session ID: ') + chalk.cyan(sessionId));
console.log(chalk.white('Prompt: ') + chalk.gray(answers.prompt.substring(0, 50) + '...'));
console.log(chalk.blue('\nš” To link this session to a commit:'));
console.log(chalk.cyan(`vibe commit -s ${sessionId}`));
}
catch (error) {
console.error(chalk.red('Failed to create session:'), error);
}
}
async function listSessions(vibehubManager) {
console.log(chalk.blue('š AI Sessions:\n'));
const sessions = await vibehubManager.getAllSessions();
if (sessions.length === 0) {
console.log(chalk.gray('No AI sessions found'));
return;
}
sessions.forEach((session, index) => {
console.log(chalk.white(`${index + 1}. ${session.id.substring(0, 8)}`));
console.log(chalk.gray(` Prompt: ${session.prompt.substring(0, 60)}...`));
console.log(chalk.gray(` Files: ${session.files.length > 0 ? session.files.join(', ') : 'None'}`));
console.log(chalk.gray(` Date: ${new Date(session.timestamp).toLocaleString()}`));
console.log('');
});
}
async function showSession(vibehubManager, sessionId) {
console.log(chalk.blue(`š Session Details: ${sessionId}\n`));
const session = await vibehubManager.getSession(sessionId);
if (!session) {
console.log(chalk.red('Session not found'));
return;
}
console.log(chalk.white('ID: ') + chalk.cyan(session.id));
console.log(chalk.white('Timestamp: ') + chalk.gray(new Date(session.timestamp).toLocaleString()));
console.log(chalk.white('Files: ') + chalk.gray(session.files.length > 0 ? session.files.join(', ') : 'None'));
console.log(chalk.white('Metadata: ') + chalk.gray(JSON.stringify(session.metadata, null, 2)));
console.log(chalk.blue('\nš¤ Prompt:'));
console.log(chalk.white(session.prompt));
console.log(chalk.blue('\nš¤ Response:'));
console.log(chalk.white(session.response));
}
async function deleteSession(vibehubManager, sessionId) {
console.log(chalk.yellow('ā ļø Delete session functionality not implemented yet'));
console.log(chalk.blue('Session ID: ') + chalk.cyan(sessionId));
}
async function interactiveSession(vibehubManager) {
const answer = await inquirer.prompt([
{
type: 'list',
name: 'action',
message: 'What would you like to do?',
choices: [
{ name: 'Create new AI session', value: 'create' },
{ name: 'List all sessions', value: 'list' },
{ name: 'Show session details', value: 'show' },
{ name: 'Delete session', value: 'delete' },
{ name: 'Exit', value: 'exit' }
]
}
]);
switch (answer.action) {
case 'create':
await createSession(vibehubManager);
break;
case 'list':
await listSessions(vibehubManager);
break;
case 'show':
const showAnswer = await inquirer.prompt([
{
type: 'input',
name: 'sessionId',
message: 'Enter session ID:'
}
]);
await showSession(vibehubManager, showAnswer.sessionId);
break;
case 'delete':
const deleteAnswer = await inquirer.prompt([
{
type: 'input',
name: 'sessionId',
message: 'Enter session ID to delete:'
}
]);
await deleteSession(vibehubManager, deleteAnswer.sessionId);
break;
case 'exit':
console.log(chalk.blue('š Goodbye!'));
break;
}
}
//# sourceMappingURL=session.js.map