@masuidrive/bloom-local-rag
Version:
RAG (Retrieval-Augmented Generation) system for local directories - Index and search your documents with AI-powered answers
82 lines • 3.61 kB
JavaScript
import { resolve } from 'path';
import { stat } from 'fs/promises';
import { join } from 'path';
import chalk from 'chalk';
import { loadConfig, loadMetadata, loadCache } from '../lib/config.js';
import { existsSync } from 'fs';
import { BLOOM_DIR, DB_DIR } from '../lib/constants.js';
function formatBytes(bytes) {
const units = ['B', 'KB', 'MB', 'GB'];
let size = bytes;
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return `${size.toFixed(2)} ${units[unitIndex]}`;
}
async function getDirSize(dirPath) {
try {
const { size } = await stat(dirPath);
return size;
}
catch {
return 0;
}
}
export async function statusCommand(options = {}) {
try {
const targetDir = options.directory ? resolve(options.directory) : (process.env.BLOOM_LOCAL_SEARCH_DIR || resolve('.'));
// Check if initialized
if (!existsSync(join(targetDir, BLOOM_DIR))) {
console.error(chalk.red('Error: Directory not initialized. Run "init" command first.'));
process.exit(1);
}
console.log(chalk.blue('Bloom Local Search Status\n'));
// Load configuration
const config = await loadConfig(targetDir);
console.log(chalk.green('Configuration:'));
console.log(chalk.gray(` Directory: ${config.directory}`));
console.log(chalk.gray(` Extensions: ${config.extensions.join(', ')}`));
console.log(chalk.gray(` Embedding: ${config.embedding.provider} (${config.embedding.model})`));
console.log(chalk.gray(` LLM: ${config.llm.provider} (${config.llm.model})`));
console.log(chalk.gray(` Chunk size: ${config.embedding.chunkSize} (overlap: ${config.embedding.chunkOverlap})`));
// Load metadata
const metadata = await loadMetadata(targetDir);
if (metadata) {
console.log(chalk.green('\nIndex Information:'));
console.log(chalk.gray(` Last indexed: ${new Date(metadata.indexedAt).toLocaleString()}`));
console.log(chalk.gray(` File count: ${metadata.fileCount}`));
console.log(chalk.gray(` Total chunks: ${metadata.totalChunks}`));
}
// Load cache to get file details
const cache = await loadCache(targetDir);
const cacheEntries = Object.entries(cache.entries);
if (cacheEntries.length > 0) {
console.log(chalk.green('\nCached Files:'));
console.log(chalk.gray(` Total: ${cacheEntries.length} files`));
// Show recently modified files
const recentFiles = cacheEntries
.sort(([, a], [, b]) => b.modifiedAt - a.modifiedAt)
.slice(0, 5);
if (recentFiles.length > 0) {
console.log(chalk.gray('\n Recently modified:'));
recentFiles.forEach(([path, entry]) => {
const date = new Date(entry.modifiedAt).toLocaleString();
console.log(chalk.gray(` ${path} (${date})`));
});
}
}
// Calculate storage size
const dbPath = join(targetDir, BLOOM_DIR, DB_DIR);
const dbSize = await getDirSize(dbPath);
console.log(chalk.green('\nStorage:'));
console.log(chalk.gray(` Database size: ${formatBytes(dbSize)}`));
console.log(chalk.blue('\n✓ Status check complete'));
}
catch (error) {
console.error(chalk.red('Error checking status:'), error);
process.exit(1);
}
}
//# sourceMappingURL=status.js.map