// tools/security-report-handler.ts — SPEC-084 AC-10
// MCP tool handler for security_report: reads audit log + config to generate report.
import { getAuditSummary, getProjectConfig } from '../engine/runtime-security/index.js';
function formatSummary(summary) {
    const lines = [
        '# Security Report',
        '',
        `**Security Level:** ${summary.securityLevel}`,
        `**Time Range:** ${summary.timeRange}`,
        '',
        '## Overview',
        '',
        `- Total calls: ${String(summary.totalCalls)}`,
        `- Threats detected: ${String(summary.threatsDetected)}`,
        `- Blocked calls: ${String(summary.blockedCalls)}`,
    ];
    if (Object.keys(summary.threatsByType).length > 0) {
        lines.push('', '## Threats by Type', '');
        for (const [type, count] of Object.entries(summary.threatsByType)) {
            lines.push(`- ${type}: ${String(count)}`);
        }
    }
    if (summary.topToolsByThreat.length > 0) {
        lines.push('', '## Top Tools by Threat Count', '');
        for (const entry of summary.topToolsByThreat) {
            lines.push(`- ${entry.tool}: ${String(entry.count)} threats`);
        }
    }
    return lines.join('\n');
}
function formatDetailed(summary) {
    const base = formatSummary(summary);
    const lines = [base, '', '## Recommendations', ''];
    if (summary.blockedCalls > 0) {
        lines.push('- Review blocked calls for potential attack patterns');
    }
    if (summary.threatsByType['path-traversal']) {
        lines.push('- Path traversal attempts detected — verify input validation on file paths');
    }
    if (summary.threatsByType['prompt-injection']) {
        lines.push('- Prompt injection patterns found — consider stricter input filtering');
    }
    if (summary.threatsByType['command-injection']) {
        lines.push('- Command injection attempts detected — never pass user input to shell commands');
    }
    if (summary.threatsByType['sensitive-data']) {
        lines.push('- Sensitive data detected in inputs — review data handling practices');
    }
    if (summary.threatsDetected === 0) {
        lines.push('- No threats detected in the selected time range. System is operating normally.');
    }
    return lines.join('\n');
}
export function handleSecurityReport(args) {
    const config = getProjectConfig(args.projectPath);
    const summary = getAuditSummary(args.projectPath, {
        timeRange: args.timeRange ?? 'all',
        securityLevel: config.level,
    });
    const format = args.format ?? 'summary';
    const text = format === 'detailed' ? formatDetailed(summary) : formatSummary(summary);
    return {
        content: [{ type: 'text', text }],
    };
}
//# sourceMappingURL=security-report-handler.js.map