// tools/update-registry.ts — Handler for the update_registry MCP tool
// Allows users to add custom framework entries to the local registry.
import { saveCustomEntry } from '../engine/registry/core.js';
/**
 * Handle update_registry tool invocations.
 * Saves a custom registry entry to data/global/registry-custom.json.
 * Custom entries override base entries with the same framework ID.
 */
export async function handleUpdateRegistry(args) {
    const entry = {
        framework: args.framework,
        displayName: args.displayName,
        ecosystem: args.ecosystem,
        frameworkVersion: args.frameworkVersion,
        lastUpdated: new Date().toISOString().split('T')[0] ?? new Date().toISOString(),
        customEntry: true,
        correctPatterns: args.correctPatterns.map((p) => ({
            pattern: p.pattern,
            example: p.example,
            since: p.since,
        })),
        deprecatedPatterns: (args.deprecatedPatterns ?? []).map((p) => ({
            pattern: p.pattern,
            replacedBy: p.replacedBy,
            severity: p.severity,
        })),
        commonMistakes: (args.commonMistakes ?? []).map((p) => ({
            pattern: p.pattern,
            example: p.example,
            replacedBy: p.replacedBy,
            severity: p.severity,
        })),
    };
    await saveCustomEntry(entry);
    const lines = [
        `## Registry actualizado`,
        '',
        `Framework **${entry.displayName}** (\`${entry.framework}\`) guardado en el registry custom.`,
        '',
        `- Ecosystem: ${entry.ecosystem}`,
        `- Version de referencia: ${entry.frameworkVersion}`,
        `- Patrones correctos: ${entry.correctPatterns.length}`,
        `- Patrones obsoletos: ${entry.deprecatedPatterns.length}`,
        `- Errores comunes: ${entry.commonMistakes.length}`,
        '',
        'La entrada se aplicara en la proxima llamada a `check_spec_accuracy`.',
        'Las entradas custom tienen prioridad sobre las entradas base del registry.',
    ];
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
    };
}
//# sourceMappingURL=update-registry.js.map