@claude-vector/cli
Version:
CLI for Claude-integrated vector search
182 lines (148 loc) β’ 6.61 kB
JavaScript
/**
* Start command - Start a new development task
*/
import chalk from 'chalk';
import ora from 'ora';
import { SessionManager, ContextManager, QueryOptimizer } from '@claude-vector/claude-tools';
import { VectorSearchEngine } from '@claude-vector/core';
export async function startCommand(task, options) {
console.log(chalk.bold('\nπ Starting New Task\n'));
const spinner = ora('Initializing session...').start();
try {
// Initialize modules
const contextManager = new ContextManager();
const queryOptimizer = new QueryOptimizer();
const sessionManager = new SessionManager();
// Initialize search engine if index exists
let searchEngine = null;
try {
searchEngine = new VectorSearchEngine();
const indexPath = '.claude-code-index';
await searchEngine.loadIndex(
`${indexPath}/embeddings.json`,
`${indexPath}/chunks.json`
);
} catch (error) {
// Search engine is optional for session start
}
// Connect modules
sessionManager.setModules({
contextManager,
searchEngine,
queryOptimizer
});
spinner.text = 'Starting new session...';
// Determine task type from options or infer from task description
const taskType = determineTaskType(task, options.type);
const session = await sessionManager.startSession(taskType, task, {
autoContext: options.auto !== false,
enableLearning: options.learning !== false
});
spinner.succeed('Session initialized');
console.log(chalk.bold('\nβ
Session ready!\n'));
console.log(chalk.bold('π Task Summary:'));
console.log(chalk.gray('Session ID:'), session.sessionId);
console.log(chalk.gray('Task Type:'), getTaskTypeEmoji(taskType), taskType);
console.log(chalk.gray('Task:'), task);
console.log(chalk.gray('Started:'), new Date().toLocaleString());
// Get session stats
const stats = await sessionManager.getCurrentSessionStatus();
if (stats && stats.contextStats) {
console.log(chalk.gray('Context:'), `${stats.contextStats.totalItems} items, ${stats.contextStats.usedTokens} tokens`);
}
if (session.relatedSessions > 0) {
console.log(chalk.bold('\nπ Context Enhancement:'));
console.log(chalk.gray(`β Loaded context from ${session.relatedSessions} related sessions`));
}
// Show next steps based on task type
console.log(chalk.bold('\nπ‘ Next steps:'));
switch (taskType) {
case 'bug-fix':
console.log(chalk.cyan('1.'), 'Review the found error patterns in context');
console.log(chalk.cyan('2.'), 'Search for specific error messages:', chalk.cyan('claude-search search "error message"'));
console.log(chalk.cyan('3.'), 'Check related test cases:', chalk.cyan('claude-search search "test logout"'));
break;
case 'feature':
console.log(chalk.cyan('1.'), 'Review similar implementations in context');
console.log(chalk.cyan('2.'), 'Search for API documentation:', chalk.cyan('claude-search search "API docs"'));
console.log(chalk.cyan('3.'), 'Look for configuration examples:', chalk.cyan('claude-search search "config"'));
break;
case 'refactor':
console.log(chalk.cyan('1.'), 'Review current implementation patterns');
console.log(chalk.cyan('2.'), 'Search for best practices:', chalk.cyan('claude-search search "best practices"'));
console.log(chalk.cyan('3.'), 'Check test coverage:', chalk.cyan('claude-search search "test"'));
break;
case 'debug':
console.log(chalk.cyan('1.'), 'Check logs and debug output');
console.log(chalk.cyan('2.'), 'Search for similar issues:', chalk.cyan('claude-search search "debug"'));
console.log(chalk.cyan('3.'), 'Trace execution flow:', chalk.cyan('claude-search search "call stack"'));
break;
default:
console.log(chalk.cyan('1.'), 'Search for relevant code:', chalk.cyan('claude-search search "query"'));
console.log(chalk.cyan('2.'), 'Check current context:', chalk.cyan('claude-search context'));
console.log(chalk.cyan('3.'), 'View session status:', chalk.cyan('claude-search status'));
}
// Show helpful tips
console.log(chalk.bold('\nπ‘ Tips:'));
console.log(chalk.gray('β’'), 'Use', chalk.cyan('claude-search context'), 'to see collected information');
console.log(chalk.gray('β’'), 'Use', chalk.cyan('claude-search error "message"'), 'for error analysis');
console.log(chalk.gray('β’'), 'Search results are automatically added to context');
// ζ£εΈΈη΅δΊ
process.exit(0);
} catch (error) {
spinner.fail(`Failed to start task: ${error.message}`);
console.error(chalk.red('\nError details:'), error.message);
// Show debugging info if available
if (error.code === 'MODULE_NOT_FOUND') {
console.log(chalk.yellow('\nπ‘ Tip: Make sure the project is initialized with'), chalk.cyan('claude-search init'));
}
process.exit(1);
}
}
/**
* Determine task type from description and options
*/
function determineTaskType(task, explicitType) {
if (explicitType) return explicitType;
const taskLower = task.toLowerCase();
// Bug fix patterns
if (taskLower.includes('fix') || taskLower.includes('bug') ||
taskLower.includes('error') || taskLower.includes('issue')) {
return 'bug-fix';
}
// Debug patterns
if (taskLower.includes('debug') || taskLower.includes('trace') ||
taskLower.includes('investigate') || taskLower.includes('why')) {
return 'debug';
}
// Refactor patterns
if (taskLower.includes('refactor') || taskLower.includes('improve') ||
taskLower.includes('clean') || taskLower.includes('optimize')) {
return 'refactor';
}
// Feature patterns
if (taskLower.includes('add') || taskLower.includes('create') ||
taskLower.includes('implement') || taskLower.includes('new')) {
return 'feature';
}
// Explore patterns
if (taskLower.includes('understand') || taskLower.includes('learn') ||
taskLower.includes('explore') || taskLower.includes('analyze')) {
return 'explore';
}
// Default to explore for general tasks
return 'explore';
}
/**
* Get emoji for task type
*/
function getTaskTypeEmoji(taskType) {
const emojis = {
'bug-fix': 'π',
'debug': 'π',
'refactor': 'β»οΈ',
'feature': 'β¨',
'explore': 'πΊοΈ'
};
return emojis[taskType] || 'π';
}