// tools/paradigm-report.ts — MCP tool: detect and report programming paradigms (SPEC-035a)
import { knowledgeStore } from '../storage/index.js';
import { detectParadigms } from '../engine/paradigm-detector.js';
import { ti } from '../i18n/index.js';
/**
 * Handle paradigm_report tool call.
 * Detects paradigms in a project and returns a structured report.
 */
export async function handleParadigmReport(args) {
    const { projectId } = args;
    const knowledge = await knowledgeStore.getKnowledge(projectId);
    if (!knowledge) {
        return {
            content: [
                {
                    type: 'text',
                    text: ti('tools.paradigm_report.notFound', { projectId }),
                },
            ],
            isError: true,
        };
    }
    const report = await detectParadigms(knowledge.projectPath);
    const text = formatReport(report);
    return {
        content: [{ type: 'text', text }],
    };
}
function formatReport(report) {
    const lines = ['## Paradigm Detection Report', ''];
    if (!report.dominant || report.dominant.confidence < 0.05) {
        lines.push('No dominant paradigm detected.');
        lines.push('');
        lines.push('The project appears to use a **hybrid/pragmatic** approach without a clear paradigm.');
        lines.push('');
        lines.push(`_Detected at: ${report.detectedAt}_`);
        return lines.join('\n');
    }
    // Dominant
    lines.push('### Dominant Paradigm');
    lines.push('');
    lines.push(`**${report.dominant.name}** — confidence: ${(report.dominant.confidence * 100).toFixed(0)}%`);
    lines.push('');
    // Mix pattern
    if (report.mixPattern !== 'none') {
        const mixLabel = report.mixPattern === 'coherent' ? 'Coherent mix' : 'Inconsistent mix';
        lines.push(`**Paradigm Mix:** ${mixLabel} | Coherence: ${(report.coherenceScore * 100).toFixed(0)}%`);
        lines.push('');
    }
    // Summary
    lines.push('### Summary');
    lines.push('');
    lines.push(report.summary);
    lines.push('');
    // All detected
    const secondary = report.all.filter((s) => s.paradigmId !== report.dominant?.paradigmId && s.confidence >= 0.05);
    if (secondary.length > 0) {
        lines.push('### Secondary Paradigms');
        lines.push('');
        lines.push('| Paradigm | Confidence | Signals |');
        lines.push('|----------|-----------|---------|');
        for (const p of secondary) {
            lines.push(`| ${p.name} | ${(p.confidence * 100).toFixed(0)}% | ${p.signals.length} |`);
        }
        lines.push('');
    }
    // Dominant signals (evidence)
    if (report.dominant.signals.length > 0) {
        lines.push('### Evidence (Top Signals)');
        lines.push('');
        const topSignals = report.dominant.signals.slice(0, 8);
        for (const sig of topSignals) {
            lines.push(`- **${sig.signalType}** \`${sig.value}\` — ${sig.location}`);
        }
        lines.push('');
    }
    if (report.dominant.confidence < 0.5) {
        lines.push('> **Note:** Confidence is below 0.5 — paradigm cannot be determined conclusively.');
        lines.push('');
    }
    lines.push(`_Detected at: ${report.detectedAt}_`);
    return lines.join('\n');
}
//# sourceMappingURL=paradigm-report.js.map