UNPKG

lorehub

Version:

Capture and surface the collective wisdom of your codebase

125 lines 5.92 kB
import React from 'react'; import { render, Box, Text } from 'ink'; import { Database } from '../../db/database.js'; import { getDbPath } from '../utils/db-config.js'; import { getRealmInfo } from '../utils/realm.js'; import { EmbeddingService } from '../../core/embeddings.js'; function RealmInfo({ realmPath }) { const [realm, setRealm] = React.useState(null); const [stats, setStats] = React.useState(null); const [loading, setLoading] = React.useState(true); React.useEffect(() => { async function loadRealmInfo() { try { const dbPath = getDbPath(); const db = new Database(dbPath); const info = await getRealmInfo(realmPath); let dbRealm = db.findRealmByPath(realmPath); if (!dbRealm) { // Create realm if it doesn't exist dbRealm = db.createRealm({ name: info.name, path: info.path, gitRemote: info.gitRemote, isMonorepo: info.isMonorepo, provinces: info.provinces, }); } // Get realm statistics const lores = db.listLoresByRealm(dbRealm.id); const loresByType = lores.reduce((acc, lore) => { acc[lore.type] = (acc[lore.type] || 0) + 1; return acc; }, {}); // Get embedding info const embeddingService = EmbeddingService.getInstance(); const modelConfig = embeddingService.getModelConfig(); setRealm({ ...info, ...dbRealm }); setStats({ totalLores: lores.length, loresByType, lastLoreDate: lores[0]?.createdAt, embeddingModel: embeddingService.getCurrentModel(), embeddingDimensions: modelConfig.dimensions, }); setLoading(false); db.close(); } catch (error) { console.error('Error loading realm info:', error); process.exit(1); } } loadRealmInfo(); }, [realmPath]); if (loading) { return React.createElement(Text, null, "Loading realm information..."); } if (!realm || !stats) { return React.createElement(Text, { color: "red" }, "Error loading realm information"); } return (React.createElement(Box, { flexDirection: "column", padding: 1 }, React.createElement(Text, { bold: true, underline: true }, "Realm Information"), React.createElement(Box, { marginTop: 1 }), React.createElement(Box, { flexDirection: "column" }, React.createElement(Text, null, React.createElement(Text, { bold: true }, "Name:"), " ", realm.name), React.createElement(Text, null, React.createElement(Text, { bold: true }, "Path:"), " ", realm.path), realm.gitRemote && (React.createElement(Text, null, React.createElement(Text, { bold: true }, "Git Remote:"), " ", realm.gitRemote)), React.createElement(Text, null, React.createElement(Text, { bold: true }, "Type:"), " ", realm.isMonorepo ? 'Monorepo' : 'Single Realm'), realm.isMonorepo && realm.provinces.length > 0 && (React.createElement(Text, null, React.createElement(Text, { bold: true }, "Provinces:"), " ", realm.provinces.join(', ')))), React.createElement(Box, { marginTop: 1 }), React.createElement(Text, { bold: true, underline: true }, "Statistics"), React.createElement(Box, { marginTop: 1 }), React.createElement(Box, { flexDirection: "column" }, React.createElement(Text, null, React.createElement(Text, { bold: true }, "Total Lores:"), " ", stats.totalLores), stats.lastLoreDate && (React.createElement(Text, null, React.createElement(Text, { bold: true }, "Last Lore:"), " ", new Date(stats.lastLoreDate).toLocaleString()))), stats.loresByType && Object.keys(stats.loresByType).length > 0 && (React.createElement(Box, { flexDirection: "column" }, React.createElement(Box, { marginTop: 1 }), React.createElement(Text, { bold: true }, "Lores by Type:"), React.createElement(Box, { flexDirection: "column", marginLeft: 2 }, Object.entries(stats.loresByType).map(([type, count]) => (React.createElement(Text, { key: type }, type, ": ", String(count))))))), React.createElement(Box, { marginTop: 1 }), React.createElement(Text, { bold: true, underline: true }, "Embedding Configuration"), React.createElement(Box, { marginTop: 1 }), React.createElement(Box, { flexDirection: "column" }, React.createElement(Text, null, React.createElement(Text, { bold: true }, "Model:"), " ", stats.embeddingModel), React.createElement(Text, null, React.createElement(Text, { bold: true }, "Dimensions:"), " ", stats.embeddingDimensions)), React.createElement(Box, { marginTop: 1 }), React.createElement(Text, { dimColor: true }, "Realm ID: ", realm.id))); } export async function renderRealmInfo() { const { waitUntilExit } = render(React.createElement(RealmInfo, { realmPath: process.cwd() })); await waitUntilExit(); } //# sourceMappingURL=realm.js.map