// tools/check-readiness.ts — Completeness checkpoint tool (SPEC-039)
import { specStore } from '../storage/index.js';
import { checkSpecReadiness } from '../engine/readiness-checker.js';
// ── Formatting helpers ───────────────────────────────────────────────────────
function formatScore(score) {
    if (score >= 90) {
        return `${score}/100 (Excellent)`;
    }
    if (score >= 70) {
        return `${score}/100 (Ready)`;
    }
    if (score >= 50) {
        return `${score}/100 (Caution)`;
    }
    return `${score}/100 (Not Ready)`;
}
function formatReport(report) {
    const lines = [];
    lines.push(`# Readiness Report — ${report.specId}`);
    lines.push('');
    lines.push(`**Score**: ${formatScore(report.score)}`);
    lines.push(`**Mode**: ${report.mode}`);
    lines.push(`**Ready for implementation**: ${report.ready ? 'YES' : 'NO'}`);
    lines.push('');
    // Score breakdown table
    lines.push('## Score Breakdown');
    lines.push('');
    lines.push('| Category | Points |');
    lines.push('|----------|--------|');
    const breakdown = report.issues.breakdown;
    if (breakdown.hu !== undefined) {
        lines.push(`| HU Completeness | ${breakdown.hu}/20 |`);
    }
    if (breakdown.criteria !== undefined) {
        lines.push(`| Acceptance Criteria | ${breakdown.criteria}/30 |`);
    }
    if (breakdown.files !== undefined) {
        lines.push(`| Files Identified | ${breakdown.files}/20 |`);
    }
    if (breakdown.dependencies !== undefined) {
        lines.push(`| Dependencies | ${breakdown.dependencies}/30 |`);
    }
    lines.push(`| **Total** | **${report.score}/100** |`);
    lines.push('');
    // Blockers
    if (report.issues.blockers.length > 0) {
        lines.push('## Blockers');
        lines.push('');
        for (const blocker of report.issues.blockers) {
            lines.push(`- BLOCKER: ${blocker}`);
        }
        lines.push('');
    }
    // Warnings
    if (report.issues.warnings.length > 0) {
        lines.push('## Warnings');
        lines.push('');
        for (const warning of report.issues.warnings) {
            lines.push(`- WARNING: ${warning}`);
        }
        lines.push('');
    }
    // Recommendations
    if (report.recommendations.length > 0) {
        lines.push('## Recommendations');
        lines.push('');
        for (const rec of report.recommendations) {
            lines.push(`- ${rec}`);
        }
        lines.push('');
    }
    // SPEC-042: Config health hint
    lines.push('## Config Health');
    lines.push('');
    lines.push('- Run `check_config_health` to detect silent misconfigurations (tsconfig coverage, CI script references, build artifact gaps) that block DoR.');
    lines.push('');
    return lines.join('\n');
}
// ── Handler ──────────────────────────────────────────────────────────────────
export async function handleCheckReadiness(args) {
    const { projectId, specId, mode = 'strict' } = args;
    const spec = await specStore.getSpec(projectId, specId);
    if (!spec) {
        return {
            content: [
                {
                    type: 'text',
                    text: `Spec '${specId}' not found in project '${projectId}'`,
                },
            ],
            isError: true,
        };
    }
    const report = await checkSpecReadiness(spec, mode);
    const formatted = formatReport(report);
    return {
        content: [{ type: 'text', text: formatted }],
    };
}
//# sourceMappingURL=check-readiness.js.map