mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
c42c88b9d6
## Major Features ### Code Intelligence System v2.0 - Tree-sitter multi-language parser (TypeScript, Python, Go, Rust, JavaScript) - Hybrid search engine (BM25 + semantic vector search with RRF fusion) - Knowledge graph with relationship extraction - RAG context builder with 70-80% token reduction - CodeIntelligenceAgent for intelligent code queries - Auto-injection into all QE agents via FleetManager ### MCP Configuration Fix - Added `generateMcpJson()` to create `.claude/mcp.json` during `aqe init` - Fixed learning persistence via `capture-task-learning.js` hook - Added `agentic-qe` to `enabledMcpjsonServers` ## CLI Commands - `aqe kg index <directory>` - Index codebase - `aqe kg search <query>` - Semantic code search - `aqe kg visualize <entity>` - Generate Mermaid diagrams - `aqe code-intel setup/enable/status` - Configuration commands ## Bug Fixes - Fixed TypeScript build errors in Code Intelligence files - Fixed FormattedContext type mismatch in CodeIntelligenceAgent - Fixed Mermaid direction type (TD → TB) - Fixed autoIndex property type in code-intelligence-init ## Issues Closed - #158 Code Intelligence System v2.0 (Epic) - #161 Wave 3: AST-Based Chunking & Embeddings - #162 Wave 4: Incremental Indexing Pipeline - #163 Wave 5: Hybrid Search & LlamaIndex RAG - #164 Wave 6: Agent Integration & CLI Commands 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
125 lines
6.4 KiB
TypeScript
125 lines
6.4 KiB
TypeScript
#!/usr/bin/env npx tsx
|
|
/**
|
|
* Index Codebase Script
|
|
*
|
|
* Uses the Code Intelligence System to index the full project codebase
|
|
* and persist the data in RuVector PostgreSQL.
|
|
*/
|
|
|
|
import chalk from 'chalk';
|
|
import ora from 'ora';
|
|
import * as path from 'path';
|
|
import { CodeIntelligenceOrchestrator } from '../src/code-intelligence/orchestrator/CodeIntelligenceOrchestrator.js';
|
|
import type { IndexingProgress } from '../src/code-intelligence/orchestrator/types.js';
|
|
|
|
async function indexCodebase(): Promise<void> {
|
|
console.log(chalk.cyan.bold('\n╔══════════════════════════════════════════════════════════════╗'));
|
|
console.log(chalk.cyan.bold('║ Code Intelligence - Full Codebase Indexing ║'));
|
|
console.log(chalk.cyan.bold('╚══════════════════════════════════════════════════════════════╝\n'));
|
|
|
|
const rootDir = process.cwd();
|
|
const startTime = Date.now();
|
|
|
|
// Initialize orchestrator
|
|
const spinner = ora('Initializing Code Intelligence System...').start();
|
|
|
|
const orchestrator = new CodeIntelligenceOrchestrator({
|
|
rootDir,
|
|
watchEnabled: false,
|
|
gitEnabled: true,
|
|
ollamaUrl: 'http://localhost:11434',
|
|
database: {
|
|
enabled: true,
|
|
host: 'localhost',
|
|
port: 5432,
|
|
database: 'ruvector_db',
|
|
user: 'ruvector',
|
|
password: 'ruvector',
|
|
},
|
|
});
|
|
|
|
try {
|
|
await orchestrator.initialize();
|
|
spinner.succeed('Code Intelligence System initialized');
|
|
|
|
// Get initial stats
|
|
const initialStats = orchestrator.getStats();
|
|
console.log(chalk.gray(`\n📊 Initial state: ${initialStats.indexer.totalChunks} chunks, ${initialStats.graph.nodeCount} nodes\n`));
|
|
|
|
// Index the src directory
|
|
const indexSpinner = ora('Indexing src/ directory...').start();
|
|
let lastProgress: IndexingProgress | null = null;
|
|
|
|
const result = await orchestrator.indexProject(path.join(rootDir, 'src'), (progress) => {
|
|
lastProgress = progress;
|
|
const pct = progress.totalFiles > 0
|
|
? Math.round((progress.processedFiles / progress.totalFiles) * 100)
|
|
: 0;
|
|
indexSpinner.text = `Indexing: ${progress.processedFiles}/${progress.totalFiles} files (${pct}%) - ${progress.chunksCreated} chunks`;
|
|
});
|
|
|
|
indexSpinner.succeed(`Indexed ${result.stats.filesIndexed} files`);
|
|
|
|
// Get final stats
|
|
const finalStats = orchestrator.getStats();
|
|
|
|
// Print summary
|
|
console.log(chalk.green.bold('\n╔══════════════════════════════════════════════════════════════╗'));
|
|
console.log(chalk.green.bold('║ INDEXING COMPLETE ║'));
|
|
console.log(chalk.green.bold('╠══════════════════════════════════════════════════════════════╣'));
|
|
console.log(chalk.white(`║ 📁 Files Indexed: ${String(result.stats.filesIndexed).padStart(6)} ║`));
|
|
console.log(chalk.white(`║ ✂️ Chunks Created: ${String(result.stats.chunksCreated).padStart(6)} ║`));
|
|
console.log(chalk.white(`║ 🧠 Embeddings Generated: ${String(result.stats.embeddingsGenerated).padStart(6)} ║`));
|
|
console.log(chalk.white(`║ 📊 Graph Nodes: ${String(result.stats.nodesCreated).padStart(6)} ║`));
|
|
console.log(chalk.white(`║ 🔗 Graph Edges: ${String(result.stats.edgesCreated).padStart(6)} ║`));
|
|
console.log(chalk.white(`║ ⏱️ Total Time: ${String(Math.round(result.stats.totalTimeMs / 1000) + 's').padStart(6)} ║`));
|
|
console.log(chalk.green.bold('╠══════════════════════════════════════════════════════════════╣'));
|
|
console.log(chalk.white(`║ 💾 Total Chunks in DB: ${String(finalStats.indexer.totalChunks).padStart(6)} ║`));
|
|
console.log(chalk.white(`║ 🌳 Total Graph Nodes: ${String(finalStats.graph.nodeCount).padStart(6)} ║`));
|
|
console.log(chalk.white(`║ 🔗 Total Graph Edges: ${String(finalStats.graph.edgeCount).padStart(6)} ║`));
|
|
console.log(chalk.green.bold('╚══════════════════════════════════════════════════════════════╝'));
|
|
|
|
// Show node breakdown
|
|
if (finalStats.graph.nodesByType) {
|
|
console.log(chalk.cyan('\n📊 Nodes by Type:'));
|
|
for (const [type, count] of Object.entries(finalStats.graph.nodesByType)) {
|
|
console.log(chalk.gray(` ${type}: ${count}`));
|
|
}
|
|
}
|
|
|
|
// Test a sample search
|
|
console.log(chalk.cyan('\n🔍 Testing sample search: "BaseAgent code intelligence"'));
|
|
const searchResult = await orchestrator.query({
|
|
query: 'BaseAgent code intelligence',
|
|
topK: 5,
|
|
includeGraphContext: true,
|
|
graphDepth: 2,
|
|
});
|
|
|
|
if (searchResult.results.length > 0) {
|
|
console.log(chalk.green(` ✅ Found ${searchResult.results.length} results in ${searchResult.metadata?.searchTimeMs || 0}ms`));
|
|
console.log(chalk.gray(` Top result: ${searchResult.results[0].entityName || path.basename(searchResult.results[0].filePath)} (score: ${searchResult.results[0].score.toFixed(4)})`));
|
|
} else {
|
|
console.log(chalk.yellow(' ⚠️ No results found'));
|
|
}
|
|
|
|
// Cleanup
|
|
await orchestrator.shutdown();
|
|
|
|
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
console.log(chalk.green.bold(`\n✅ Codebase indexing complete in ${totalTime}s\n`));
|
|
|
|
} catch (error) {
|
|
spinner.fail('Failed to index codebase');
|
|
console.error(chalk.red(`\n❌ Error: ${(error as Error).message}\n`));
|
|
await orchestrator.shutdown();
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Run
|
|
indexCodebase().catch((error) => {
|
|
console.error('Fatal error:', error);
|
|
process.exit(1);
|
|
});
|