UNPKG

hikma-engine

Version:

Code Knowledge Graph Indexer - A sophisticated TypeScript-based indexer that transforms Git repositories into multi-dimensional knowledge stores for AI agents

103 lines (102 loc) • 4.86 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.displaySuccess = displaySuccess; exports.displayCommandHeader = displayCommandHeader; exports.displayProgress = displayProgress; exports.displayRAGExplanation = displayRAGExplanation; exports.displayResults = displayResults; const chalk_1 = __importDefault(require("chalk")); const cli_table3_1 = __importDefault(require("cli-table3")); function displaySuccess(message, metrics) { console.log(chalk_1.default.green(`\nāœ… ${message}`)); if (metrics) { console.log(chalk_1.default.gray('='.repeat(Math.min(message.length + 3, 50)))); Object.entries(metrics).forEach(([key, value]) => { const formattedKey = chalk_1.default.cyan(key); const formattedValue = typeof value === 'number' ? chalk_1.default.yellow(value.toLocaleString()) : chalk_1.default.white(String(value)); console.log(`${formattedKey}: ${formattedValue}`); }); } } function displayCommandHeader(command, description) { console.log(chalk_1.default.blue(`\nšŸš€ ${command}`)); console.log(chalk_1.default.gray(description)); console.log(chalk_1.default.gray('-'.repeat(50))); } function displayProgress(message) { console.log(chalk_1.default.blue(`šŸ”„ ${message}`)); } function displayRAGExplanation(query, ragResponse) { const { explanation, model, device, finishReason, usage } = ragResponse; console.log(chalk_1.default.green('\n🧠 Code Explanation:')); console.log(chalk_1.default.gray('='.repeat(60))); console.log(chalk_1.default.cyan(`Query: "${query}"`)); console.log(chalk_1.default.gray(`Model: ${model}${device ? ` (${device})` : ''}`)); console.log(chalk_1.default.gray('='.repeat(60))); console.log(); if (explanation) { const paragraphs = explanation.split('\n\n').filter((p) => p.trim()); paragraphs.forEach((paragraph, index) => { if (index > 0) console.log(); console.log(chalk_1.default.white(paragraph.trim())); }); } else { console.log(chalk_1.default.yellow('No explanation generated.')); } console.log(); console.log(chalk_1.default.gray('='.repeat(60))); if (finishReason && finishReason !== 'stop') { console.log(chalk_1.default.yellow(`āš ļø Generation finished due to: ${finishReason}`)); } if (usage?.total_tokens) { console.log(chalk_1.default.gray(`Tokens used: total=${usage.total_tokens}${usage.prompt_tokens !== undefined ? `, prompt=${usage.prompt_tokens}` : ''}${usage.completion_tokens !== undefined ? `, completion=${usage.completion_tokens}` : ''}`)); } console.log(chalk_1.default.green('✨ Code explanation completed')); } function displayResults(results, title) { console.log(chalk_1.default.green(`\nšŸ“‹ ${title}`)); console.log(chalk_1.default.gray('='.repeat(title.length + 3))); if (results.length === 0) { console.log(chalk_1.default.yellow('\nšŸ“­ No results found. Try adjusting your search criteria.')); return; } const table = new cli_table3_1.default({ head: [ chalk_1.default.bold('Node ID'), chalk_1.default.bold('Type'), chalk_1.default.bold('File Path'), chalk_1.default.bold('Similarity'), chalk_1.default.bold('Source Text Preview'), ], colWidths: [12, 15, 35, 12, 50], wordWrap: true, style: { head: ['cyan'], border: ['gray'] }, }); results.forEach((result, index) => { const similarity = result.similarity ? `${(result.similarity * 100).toFixed(1)}%` : 'N/A'; const preview = result.node?.sourceText ? result.node.sourceText.length > 80 ? result.node.sourceText.substring(0, 80).replace(/\n/g, ' ') + '...' : result.node.sourceText.replace(/\n/g, ' ') : 'N/A'; const nodeId = result.node?.nodeId || 'N/A'; const nodeType = result.node?.nodeType || 'N/A'; const filePath = result.node?.filePath || 'N/A'; table.push([ chalk_1.default.dim(`#${index + 1} `) + nodeId.substring(0, 8), chalk_1.default.blue(nodeType), chalk_1.default.gray(filePath.length > 30 ? '...' + filePath.substring(filePath.length - 30) : filePath), similarity === 'N/A' ? chalk_1.default.gray(similarity) : chalk_1.default.green(similarity), chalk_1.default.white(preview), ]); }); console.log(table.toString()); console.log(chalk_1.default.green(`\nšŸ“Š Displayed ${results.length} result${results.length === 1 ? '' : 's'}`)); }