// tools/type-safety-gate.ts — SPEC-968: Gate that blocks update_status(done) on TS anti-patterns
import { scanTypeSafety } from '../engine/type-safety-gate.js';
import { compactResult, compactError, formatScore, formatTable } from './output-formatter.js';
export function handleTypeSafetyGate(args) {
    const { projectPath, specId, waiver } = args;
    if (!projectPath) {
        return compactError('projectPath is required.');
    }
    const result = scanTypeSafety(projectPath, waiver);
    const lines = [];
    lines.push(`# Type Safety Gate — ${specId}`);
    lines.push('');
    lines.push(formatScore('Health Score', result.score, 100));
    lines.push(`**Passed**: ${result.passed ? 'YES' : 'NO'}`);
    lines.push(`**any violations**: ${result.anyCount}`);
    lines.push(`**@ts-ignore / @ts-expect-error violations**: ${result.tsIgnoreCount}`);
    lines.push(`**noImplicitAny violations**: ${result.noImplicitAnyCount}`);
    lines.push('');
    if (result.violations.length > 0) {
        lines.push(formatTable(result.violations.map((v) => ({
            File: v.file,
            Line: v.line,
            Type: v.type,
            Message: v.message,
        })), ['File', 'Line', 'Type', 'Message'], 'Violations'));
        lines.push('');
    }
    if (result.suggestions.length > 0) {
        lines.push('## Suggestions');
        lines.push('');
        for (const s of result.suggestions) {
            lines.push(`- ${s}`);
        }
        lines.push('');
    }
    const text = lines.join('\n');
    if (!result.passed) {
        return {
            ...compactError(text),
            structuredContent: result,
        };
    }
    return {
        ...compactResult(text),
        structuredContent: result,
    };
}
//# sourceMappingURL=type-safety-gate.js.map