// tools/check-spec-accuracy.ts — Handler for the check_spec_accuracy MCP tool
// Validates spec content against the framework registry to detect hallucinated APIs.
import { validateSpecContent, formatReport } from '../engine/registry/core.js';
import { formatSuccess, formatWarning, addNextSteps } from './response-helpers.js';
import { t } from '../i18n/index.js';
/**
 * Handle check_spec_accuracy tool invocations.
 * Accepts spec text and optional framework list, returns a Markdown accuracy report.
 */
export async function handleCheckSpecAccuracy(args) {
    const { specContent, frameworks } = args;
    const report = await validateSpecContent(specContent, frameworks);
    const markdown = formatReport(report);
    const scoreIcon = report.score >= 80 ? '✅' : report.score >= 50 ? '⚠️' : '❌';
    const title = t('tools.response.accuracyTitle');
    const summaryLines = [
        `${scoreIcon} **Score:** ${report.score}/100`,
        `**Problemas encontrados:** ${report.issues.length}`,
        `**Frameworks detectados:** ${report.frameworksDetected.join(', ') || 'ninguno'}`,
    ];
    if (report.frameworksNotInRegistry.length > 0) {
        summaryLines.push(`**Frameworks sin datos en registry:** ${report.frameworksNotInRegistry.join(', ')}`);
    }
    if (report.staleRegistryEntries.length > 0) {
        summaryLines.push(`**Entradas desactualizadas (>180 dias):** ${report.staleRegistryEntries.join(', ')}`);
    }
    const body = [...summaryLines, '', markdown].join('\n');
    let nextSteps;
    if (report.score < 50) {
        nextSteps = ['Run `reconcile_spec` to sync plan with code', 'Review acceptance criteria'];
    }
    else if (report.score < 80) {
        nextSteps = ['Run `reconcile_spec` to fix drift', 'Check failing criteria'];
    }
    else {
        nextSteps = ['Spec is well aligned', 'Run `validate` for full coverage check'];
    }
    let output;
    if (report.score >= 80) {
        output = formatSuccess(title, body, nextSteps);
    }
    else if (report.score >= 50) {
        output = formatWarning(title, body, nextSteps);
    }
    else {
        output = addNextSteps(`❌ **${title}**\n\n${body}`, nextSteps);
    }
    return {
        content: [{ type: 'text', text: output }],
    };
}
//# sourceMappingURL=check-spec-accuracy.js.map