import { auditDeps } from './index.js';
/**
 * Run a pre-spec dependency check for the given project.
 * Calls auditDeps() and surfaces warnings if HIGH/CRITICAL vulnerabilities
 * or abandoned packages are found.
 * Returns a PreSpecDepResult that can be embedded in HU.md output.
 */
export async function runPreSpecDepCheck(projectPath, _knowledge) {
    let report;
    try {
        report = await auditDeps(projectPath);
    }
    catch {
        // If audit fails (e.g. no manifest), return clean result — never block spec creation
        return {
            hasWarnings: false,
            criticalCount: 0,
            highCount: 0,
            abandonedCount: 0,
            warningLines: [],
        };
    }
    const criticalVulnEntries = report.critical.filter((e) => e.vulns.some((v) => v.severity === 'critical'));
    const highVulnEntries = report.critical.filter((e) => e.vulns.some((v) => v.severity === 'high'));
    const abandonedEntries = [
        ...report.critical.filter((e) => e.abandoned.isAbandoned),
        ...report.warnings.filter((e) => e.abandoned.isAbandoned),
    ];
    const criticalCount = criticalVulnEntries.length;
    const highCount = highVulnEntries.length;
    const abandonedCount = abandonedEntries.length;
    const hasWarnings = criticalCount > 0 || highCount > 0 || abandonedCount > 0;
    const warningLines = buildWarningLines(criticalVulnEntries.map((e) => e.name), highVulnEntries.map((e) => e.name), abandonedEntries.map((e) => e.name));
    return { hasWarnings, criticalCount, highCount, abandonedCount, warningLines };
}
function buildWarningLines(criticalPkgs, highPkgs, abandonedPkgs) {
    const lines = [];
    if (criticalPkgs.length > 0) {
        lines.push(`- **CRITICAL vulnerabilities** in: ${criticalPkgs.join(', ')}`);
    }
    if (highPkgs.length > 0) {
        lines.push(`- **HIGH vulnerabilities** in: ${highPkgs.join(', ')}`);
    }
    if (abandonedPkgs.length > 0) {
        lines.push(`- **Abandoned packages**: ${abandonedPkgs.join(', ')}`);
    }
    return lines;
}
//# sourceMappingURL=pre-spec-check.js.map