/**
 * Phase 10: P0/P1 知识资产 schema 完整性
 */
import fs from "node:fs";
import path from "node:path";
import { findFilesRecursive } from "./helpers.js";
export async function check(ctx, hardFail, _info) {
    const rootDir = ctx.rootDir;
    const matter = (await import("gray-matter")).default;
    const { validateKnowledgeAssetFrontmatter } = await import("../../knowledge/knowledge_asset_schema.js");
    const knowledgeDir = path.join(rootDir, "templates", "knowledge");
    if (!fs.existsSync(knowledgeDir))
        return;
    const mdFiles = findFilesRecursive(knowledgeDir, ".md");
    for (const filePath of mdFiles) {
        const raw = fs.readFileSync(filePath, "utf-8");
        const { data: frontmatter } = matter(raw);
        if (!frontmatter || Object.keys(frontmatter).length === 0)
            continue;
        if (!frontmatter.asset_kind)
            continue;
        const findings = validateKnowledgeAssetFrontmatter(frontmatter, filePath);
        for (const f of findings) {
            if (f.severity === "hard_fail") {
                hardFail(`KA_SCHEMA_${f.kind}`, f.message_zh, [filePath], f.asset_id, "旧 validate-release 不独立校验知识资产 schema", "补齐缺失的 frontmatter 字段");
            }
        }
    }
}
//# sourceMappingURL=checkKnowledgeAssetSchemaP0.js.map