// Planu — multi_agent_review tool handler (SPEC-483)
import { z } from 'zod';
import { runMultiAgentReview } from './orchestrator.js';
// ---------------------------------------------------------------------------
// Zod input schema (exported for registration)
// ---------------------------------------------------------------------------
export const MultiAgentReviewInputSchema = {
    projectPath: z.string().describe('Absolute path to the project root directory to review.'),
    files: z
        .array(z.string())
        .optional()
        .describe('Optional list of relative file paths to restrict analysis. ' +
        'When omitted the full project is scanned.'),
    diff: z
        .string()
        .optional()
        .describe('Optional unified diff string. When provided the analyzers focus on changed lines.'),
};
// ---------------------------------------------------------------------------
// Markdown rendering
// ---------------------------------------------------------------------------
const SEVERITY_EMOJI = {
    critical: '🔴',
    high: '🟠',
    medium: '🟡',
    low: '🔵',
    nit: '⚪',
};
function renderFindingRow(f) {
    const loc = f.line > 0 ? `${f.file}:${String(f.line)}` : f.file;
    const hint = f.fixHint !== undefined ? ` _${f.fixHint}_` : '';
    return `| ${SEVERITY_EMOJI[f.severity]} ${f.severity} | \`${loc}\` | \`${f.ruleId}\` | ${f.message}${hint} |`;
}
function renderReport(report) {
    const lines = [
        '## Multi-Agent Review',
        '',
        `**${String(report.totalFindings)} findings** | ` +
            Object.entries(report.counts)
                .filter(([, c]) => c > 0)
                .map(([s, c]) => `${SEVERITY_EMOJI[s]} ${s}: ${String(c)}`)
                .join(' · '),
        '',
    ];
    if (report.totalFindings === 0) {
        lines.push('✅ No issues found. All analyzers passed.');
        return lines.join('\n');
    }
    const severities = ['critical', 'high', 'medium', 'low', 'nit'];
    for (const sev of severities) {
        const group = report.findings.filter((f) => f.severity === sev);
        if (group.length === 0) {
            continue;
        }
        lines.push(`### ${SEVERITY_EMOJI[sev]} ${sev.charAt(0).toUpperCase() + sev.slice(1)} (${String(group.length)})`);
        lines.push('');
        lines.push('| Severity | Location | Rule | Description |');
        lines.push('|----------|----------|------|-------------|');
        for (const f of group) {
            lines.push(renderFindingRow(f));
        }
        lines.push('');
    }
    lines.push(`_Reviewed at: ${report.reviewedAt} · Files scanned: ${String(report.scannedFiles.length)}_`);
    return lines.join('\n');
}
// ---------------------------------------------------------------------------
// Handler
// ---------------------------------------------------------------------------
export async function handleMultiAgentReview(args) {
    const report = await runMultiAgentReview(args);
    const text = renderReport(report);
    return {
        content: [{ type: 'text', text }],
    };
}
//# sourceMappingURL=index.js.map