/**
 * 产物 Schema 注册中心 — 集中管理所有 19 种产物类型的结构定义。
 *
 * 职责：
 * 1. 定义 ArtifactSchema 接口（必填章节、表格、字段、附属产物）
 * 2. 注册所有 19 种 ArtifactKind 的完整 schema
 * 3. 提供按 kind 查询、格式化为 prompt 注入文本的能力
 *
 * 设计决策：
 * - Schema 是结构契约（强制），与模板正文（参考范例）解耦
 * - Section 名称取自模板 ## 标题的关键文本，匹配时容许编号前缀
 * - P0 契约（standard_asset_contract.ts）中不完整的 sections 已从此处补齐
 */
// ── Schema 注册表 ──
/**
 * 全量产物 Schema 注册表。
 *
 * 数据来源：
 * - P0 契约（standard_asset_contract.ts）的 kind_specific 数据
 * - 30 个模板文件（templates/artifacts/shared/*.md）的 ## 标题和表格结构
 * - 原有 P0 契约只覆盖 3-4 个 sections，此处已从模板补齐至完整章节
 */
const ARTIFACT_SCHEMAS = new Map([
    // ── P0 产物类型（原有契约已升级） ──
    ["prototype_spec", {
            kind: "prototype_spec",
            // 原 P0 只有 3 个章节（功能概述/页面结构/交互流程），从模板补齐至 10 个
            required_sections: [
                "源码提取约束",
                "页面元数据",
                "设计令牌",
                "页面布局树",
                "组件数据绑定",
                "交互流转",
                "组件视觉状态",
                "响应式断点",
                "动效规范",
                "边界与异常分支",
            ],
            required_tables: [
                "色彩令牌表",
                "间距与圆角表",
                "字体令牌表",
                "字段映射表",
                "组件视觉状态表",
                "响应式断点表",
                "动效规范表",
            ],
            required_fields: {
                "色彩令牌表": ["令牌名", "色值", "用途"],
                "间距与圆角表": ["令牌名", "值", "用途"],
                "字体令牌表": ["令牌名", "值", "用途"],
                "字段映射表": ["UI 元素", "绑定字段", "格式化规则", "动态行为"],
                "组件视觉状态表": ["组件", "状态", "视觉变化"],
                "响应式断点表": ["断点", "宽度范围", "布局变化"],
                "动效规范表": ["交互", "动效", "时长", "缓动函数"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空功能描述", "空章节标题"],
            template_file: "原型说明模版.md",
        }],
    ["design_doc", {
            kind: "design_doc",
            // 原 P0 只有 4 个章节（系统概述/架构决策/技术选型/模块设计），从模板补齐至 12 个
            required_sections: [
                "决策记录",
                "架构决策状态总表",
                "需求概要",
                "模块划分",
                "业务流程",
                "基础设施架构",
                "技术选型与依据",
                "数据库与API专项产物引用",
                "状态机定义",
                "非功能需求",
                "未决项",
                "扩展点",
            ],
            required_tables: [
                "架构决策状态总表",
                "技术选型表",
                "风险表",
            ],
            required_fields: {
                "架构决策状态总表": ["架构域", "状态", "结论", "影响产物"],
                "技术选型表": ["技术决策", "候选方案", "最终选择", "选择理由"],
                "风险表": ["风险", "影响", "概率", "应对方案"],
            },
            required_artifacts: ["Mermaid 架构图"],
            forbidden_gaps: ["空章节标题", "缺失 Mermaid 代码块"],
            template_file: "架构设计模版.md",
        }],
    ["api_spec", {
            kind: "api_spec",
            // 原 P0 只有 2 个章节（接口概览/请求响应规范），从模板补齐至 9 个
            required_sections: [
                "基本信息",
                "请求 Header 字段",
                "请求 Path",
                "请求体字段",
                "响应体字段",
                "错误与副作用",
                "验收场景",
                "枚举值定义",
                "页面交互映射",
            ],
            required_tables: [
                "基本信息表",
                "请求Header字段表",
                "请求Path/Query字段表",
                "请求体字段表",
                "响应体字段表",
                "错误与副作用表",
                "验收场景表",
                "枚举值定义表",
                "页面交互映射表",
            ],
            required_fields: {
                "基本信息表": ["endpoint_id", "用途", "调用端", "权限", "幂等"],
                "请求Header字段表": ["字段路径", "类型", "必填", "格式", "说明"],
                "请求Path/Query字段表": ["字段路径", "类型", "必填", "说明"],
                "请求体字段表": ["字段路径", "类型", "必填", "枚举", "数据映射", "说明"],
                "响应体字段表": ["字段路径", "类型", "必有", "可空", "数据来源", "说明"],
                "错误与副作用表": ["业务码", "HTTP状态", "触发条件", "用户提示"],
                "验收场景表": ["场景", "输入", "预期响应", "验证证据"],
                "枚举值定义表": ["枚举名", "值", "含义"],
                "页面交互映射表": ["页面操作", "触发接口", "加载状态", "成功行为", "失败行为"],
            },
            required_artifacts: ["OpenAPI 文件"],
            forbidden_gaps: ["endpoint缺请求或响应字段表"],
            template_file: "API接口规格文档模版.md",
        }],
    ["verification_report", {
            kind: "verification_report",
            // 原 P0（consistency_report）4 个章节，从模板补齐至 6 个
            required_sections: [
                "产物清单与Hash",
                "用户确认与决策引用",
                "验证结果",
                "跨产物追踪与冲突处理",
                "Implementation Readiness",
                "残余风险与返工要求",
            ],
            required_tables: [
                "跨文档追踪矩阵",
            ],
            required_fields: {
                "跨文档追踪矩阵": ["产物", "Hash", "验证结果"],
            },
            required_artifacts: ["设计产物引用列表"],
            forbidden_gaps: ["空验收结论"],
            template_file: "设计一致性验收报告模版.md",
        }],
    // ── P1 产物类型（从模板提取完整 schema） ──
    ["detailed_design", {
            kind: "detailed_design",
            required_sections: [
                "设计前提",
                "数据结构",
                "接口定义",
                "核心逻辑",
                "前后端适配矩阵",
                "菜单权限映射",
            ],
            required_tables: [
                "前后端适配矩阵表",
                "菜单权限映射表",
            ],
            required_fields: {
                "前后端适配矩阵表": ["前端页面", "后端接口", "数据字段映射", "交互行为"],
                "菜单权限映射表": ["菜单路径", "角色", "权限标识", "关联接口"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空章节标题"],
            template_file: "详细设计模版.md",
        }],
    ["api_design", {
            kind: "api_design",
            // 接口对接方案 — 第三方集成场景
            required_sections: [
                "第三方服务概况",
                "认证方式",
                "接口清单",
                "数据映射",
                "错误码映射",
                "容错策略",
                "Mock方案",
            ],
            required_tables: [
                "接口清单表",
                "数据映射表",
                "错误码映射表",
            ],
            required_fields: {
                "接口清单表": ["接口", "方法", "路径", "用途"],
                "数据映射表": ["我方字段", "我方类型", "对方字段", "对方类型", "转换规则"],
                "错误码映射表": ["对方错误码", "含义", "我方错误码", "用户提示", "处理策略"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空章节标题"],
            template_file: "接口对接方案模版.md",
        }],
    ["requirement_analysis", {
            kind: "requirement_analysis",
            required_sections: [
                "需求来源",
                "功能点清单",
                "术语表",
                "未确认项",
                "写操作失败反馈",
                "菜单权限规划",
                "冲突与越界项",
            ],
            required_tables: [
                "功能点清单表",
                "术语表",
                "未确认项表",
                "写操作失败反馈表",
                "菜单权限规划表",
                "冲突与越界项表",
            ],
            required_fields: {
                "功能点清单表": ["编号", "功能点", "页面/接口", "业务规则", "验收标准"],
                "术语表": ["术语", "含义", "同义词"],
                "未确认项表": ["编号", "问题", "影响范围", "阻塞程度"],
                "写操作失败反馈表": ["操作", "失败场景", "用户提示", "重试建议"],
                "菜单权限规划表": ["菜单路径", "关联功能", "角色", "权限标识"],
                "冲突与越界项表": ["项", "类型", "来源", "处理方式"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空功能描述"],
            template_file: "需求分析模版.md",
        }],
    ["test_plan", {
            kind: "test_plan",
            required_sections: [
                "测试范围",
                "测试条目",
                "环境与数据",
                "执行顺序",
                "验收标准",
            ],
            required_tables: [
                "测试条目表",
            ],
            required_fields: {
                "测试条目表": ["编号", "功能点", "测试类型", "覆盖策略", "优先级"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空章节标题"],
            template_file: "测试计划模版.md",
        }],
    ["task_breakdown", {
            kind: "task_breakdown",
            // 切片计划
            required_sections: [
                "项目信息",
                "切片列表",
                "执行顺序与缓冲安排",
                "风险标注",
            ],
            required_tables: [],
            required_artifacts: [],
            forbidden_gaps: ["空章节标题"],
            template_file: "切片计划模版.md",
        }],
    ["task_plan", {
            kind: "task_plan",
            // 与 task_breakdown 共享模板，但侧重排期与时间线
            required_sections: [
                "项目信息",
                "切片列表",
                "执行顺序与缓冲安排",
                "风险标注",
            ],
            required_tables: [],
            required_artifacts: [],
            forbidden_gaps: ["空章节标题"],
            template_file: "切片计划模版.md",
        }],
    ["root_cause", {
            kind: "root_cause",
            required_sections: [
                "问题概述",
                "复现步骤",
                "根因分析",
                "修复方案",
                "预防措施",
            ],
            required_tables: [
                "假设验证记录表",
            ],
            required_fields: {
                "假设验证记录表": ["假设", "验证方式", "结果", "结论"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空根因分析"],
            template_file: "Bug分析模版.md",
        }],
    ["incident_review", {
            kind: "incident_review",
            required_sections: [
                "故障概要",
                "时间线",
                "根因分析",
                "修复过程",
                "暴露的监控盲区",
                "后续改进项",
            ],
            required_tables: [
                "时间线表",
                "监控盲区表",
                "后续改进项表",
            ],
            required_fields: {
                "时间线表": ["时间", "事件", "操作人"],
                "监控盲区表": ["监控项", "当前状态", "改进方案"],
                "后续改进项表": ["编号", "改进项", "类型", "责任人", "计划时间"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空时间线"],
            template_file: "故障复盘模版.md",
        }],
    ["review_report", {
            kind: "review_report",
            required_sections: [
                "审查信息",
                "审查结果",
                "发现项",
                "审查清单校验",
            ],
            required_tables: [
                "发现项表",
                "审查清单校验表",
            ],
            required_fields: {
                "发现项表": ["#", "维度", "严重程度", "文件", "描述", "建议"],
                "审查清单校验表": ["检查项", "通过"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空审查结果"],
            template_file: "代码审查报告模版.md",
        }],
    ["tech_decision_record", {
            kind: "tech_decision_record",
            required_sections: [
                "决策标题",
                "背景",
                "选项",
                "结论",
                "原因",
            ],
            required_tables: [],
            required_artifacts: [],
            forbidden_gaps: ["空结论"],
            template_file: "ADR模版.md",
        }],
    ["migration_plan", {
            kind: "migration_plan",
            required_sections: [
                "迁移范围",
                "兼容性分析",
                "迁移路径",
                "风险评估",
                "资源与时间",
            ],
            required_tables: [
                "兼容性分析表",
                "迁移阶段表",
            ],
            required_fields: {
                "兼容性分析表": ["变更项", "当前", "目标", "兼容性", "适配方案"],
                "迁移阶段表": ["阶段", "内容", "预计工时", "回滚方案"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空章节标题"],
            template_file: "迁移评估模版.md",
        }],
    // ── P2 产物类型（验收清单/辅助型） ──
    ["acceptance_checklist", {
            kind: "acceptance_checklist",
            // 验收清单的章节结构统一为"验收项"
            required_sections: [
                "验收项",
            ],
            required_tables: [],
            required_artifacts: [],
            forbidden_gaps: ["空验收项"],
            template_file: "通用质量验收清单.md",
        }],
    ["interaction_spec", {
            kind: "interaction_spec",
            // 交互规约 — 与 prototype_spec 共享部分结构，侧重交互流转
            required_sections: [
                "交互流转",
                "组件视觉状态",
                "响应式断点",
                "动效规范",
                "边界与异常分支",
            ],
            required_tables: [
                "组件视觉状态表",
                "响应式断点表",
                "动效规范表",
            ],
            required_fields: {
                "组件视觉状态表": ["组件", "状态", "视觉变化"],
                "响应式断点表": ["断点", "宽度范围", "布局变化"],
                "动效规范表": ["交互", "动效", "时长", "缓动函数"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空章节标题"],
            template_file: "原型说明模版.md",
        }],
    ["domain_model", {
            kind: "domain_model",
            // 领域模型 — OOD 设计摘要
            required_sections: [
                "适用性",
                "对象与职责",
                "接口与依赖方向",
                "变化点与SOLID复验",
            ],
            required_tables: [
                "对象与职责表",
                "接口与依赖方向表",
                "变化点与SOLID复验表",
            ],
            required_fields: {
                "对象与职责表": ["对象/模块", "单一职责", "协作者", "禁止承担的职责"],
                "接口与依赖方向表": ["接口/端口", "提供者", "消费者", "依赖方向"],
                "变化点与SOLID复验表": ["变化点", "SRP", "OCP", "LSP", "ISP", "DIP"],
            },
            required_artifacts: [],
            forbidden_gaps: ["空章节标题"],
            template_file: "OOD设计摘要模版.md",
        }],
    ["knowledge_rule", {
            kind: "knowledge_rule",
            // 知识规则 — 内部机制产物，无固定模板结构
            required_sections: [],
            required_tables: [],
            required_artifacts: [],
            forbidden_gaps: [],
        }],
    ["custom", {
            kind: "custom",
            // 自定义产物 — 无固定 schema
            required_sections: [],
            required_tables: [],
            required_artifacts: [],
            forbidden_gaps: [],
        }],
]);
// ── 查询函数 ──
/**
 * 获取指定产物类型的 Schema。
 * @returns Schema 或 undefined（未知类型）
 */
export function getArtifactSchema(kind) {
    return ARTIFACT_SCHEMAS.get(kind);
}
/**
 * 检查指定产物类型是否有已注册的 Schema。
 */
export function hasArtifactSchema(kind) {
    return ARTIFACT_SCHEMAS.has(kind);
}
/**
 * 获取所有已注册的 Schema（不含 custom 和 knowledge_rule）。
 */
export function getAllArtifactSchemas() {
    return Array.from(ARTIFACT_SCHEMAS.values())
        .filter((s) => s.kind !== "custom" && s.kind !== "knowledge_rule");
}
/**
 * 获取所有已注册 Schema 的 kind 列表。
 */
export function getRegisteredSchemaKinds() {
    return Array.from(ARTIFACT_SCHEMAS.keys());
}
/**
 * 获取有实质结构约束的 Schema 列表（required_sections 或 required_tables 非空）。
 */
export function getStructuralSchemas() {
    return Array.from(ARTIFACT_SCHEMAS.values())
        .filter((s) => s.required_sections.length > 0 || s.required_tables.length > 0);
}
// ── Schema 匹配辅助 ──
/**
 * 灵活的章节标题匹配 — 容许编号前缀（如 "1. "、"2.1 "）。
 *
 * 匹配规则：
 * - `## 页面元数据` → 匹配 section "页面元数据"
 * - `## 1. 页面元数据` → 匹配 section "页面元数据"
 * - `### 2.1 色彩` → 匹配 section "色彩"
 */
export function matchSection(content, sectionName) {
    const escaped = escapeRegExp(sectionName);
    // 容许编号前缀：## 1. 页面元数据 或 ## 页面元数据
    const regex = new RegExp(`#+\\s*(?:\\d+(?:\\.\\d+)*[.、\\s]+)?${escaped}`, "i");
    return regex.test(content);
}
/**
 * 在内容中查找所有缺失的必填章节。
 * @returns 缺失的章节名称列表
 */
export function findMissingSections(content, schema) {
    return schema.required_sections.filter((section) => !matchSection(content, section));
}
/**
 * 在内容中查找所有缺失的必填表格。
 * @returns 缺失的表格名称列表
 */
export function findMissingTables(content, schema) {
    if (schema.required_tables.length === 0)
        return [];
    return schema.required_tables.filter((table) => {
        // 提取表格关键词（去掉"表"后缀，取前 8 字符）
        const keyword = table.replace(/表$/, "").slice(0, 8);
        const regex = new RegExp(`\\|.*${escapeRegExp(keyword)}`, "i");
        return !content.includes("|") || !regex.test(content);
    });
}
// ── Prompt 格式化（供 Batch 5 知识注入使用） ──
/**
 * 将 ArtifactSchema 格式化为可注入 prompt 的结构约束文本。
 *
 * 输出格式：
 * ```
 * ## 产物结构约束：prototype_spec
 * 必填章节：页面元数据、设计令牌、页面布局树...
 * 必填表格：色彩令牌表、间距与圆角表...
 * 表格必填列：
 *   色彩令牌表 → 令牌名、色值、用途
 *   ...
 * ```
 */
export function formatSchemaForPrompt(schema) {
    const lines = [];
    lines.push(`## 产物结构约束：${schema.kind}`);
    if (schema.required_sections.length > 0) {
        lines.push(`必填章节：${schema.required_sections.join("、")}`);
    }
    if (schema.required_tables.length > 0) {
        lines.push(`必填表格：${schema.required_tables.join("、")}`);
    }
    if (schema.required_fields) {
        const fieldLines = Object.entries(schema.required_fields)
            .map(([table, fields]) => `  ${table} → ${fields.join("、")}`);
        if (fieldLines.length > 0) {
            lines.push("表格必填列：");
            lines.push(...fieldLines);
        }
    }
    if (schema.required_artifacts && schema.required_artifacts.length > 0) {
        lines.push(`必填附属产物：${schema.required_artifacts.join("、")}`);
    }
    if (schema.forbidden_gaps && schema.forbidden_gaps.length > 0) {
        lines.push(`禁止空白：${schema.forbidden_gaps.join("、")}`);
    }
    return lines.join("\n");
}
/** 内置占位符正则模式（16 种） */
const BUILTIN_PLACEHOLDER_PATTERNS = [
    /待补充|待填[写写]|请补充|此处省略/,
    /TODO|TBD|FIXME/i,
    /暂无|待定|待完善/,
    /placeholder|to be filled|not yet/i,
    /n\/a|N\/A/,
    /^.{0,5}\.{3,}.{0,5}$/, // "..." 或 "……"
];
/**
 * 检测空洞章节 — 标题存在但正文内容不足阈值。
 *
 * 算法：
 * 1. 按行提取所有 ## 级别的标题
 * 2. 对每个标题，取其到下一个同级标题之间的正文
 * 3. 正文预处理：去掉 markdown 格式标记、代码块行、表格行、空行
 * 4. 用 matchSection() 与 schema.required_sections 匹配
 * 5. 匹配成功的章节，正文长度 < threshold → 空洞
 */
export function findHollowSections(content, schema, threshold = 50) {
    const lines = content.split("\n");
    const headings = [];
    // 提取所有 markdown 标题
    for (let i = 0; i < lines.length; i++) {
        const match = lines[i].match(/^(#{1,4})\s+(.+)/);
        if (match) {
            headings.push({
                name: match[2].replace(/\s*#\s*$/, "").trim(), // 去掉尾部的 #
                line: i + 1,
                level: match[1].length,
            });
        }
    }
    const results = [];
    for (const section of schema.required_sections) {
        // 找到匹配的标题
        const headingIdx = headings.findIndex((h) => {
            // 复用 matchSection 的逻辑 — 容许编号前缀
            const escaped = escapeRegExp(section);
            const regex = new RegExp(`^(?:\\d+(?:\\.\\d+)*[.、\\s]+)?${escaped}$`, "i");
            return regex.test(h.name);
        });
        if (headingIdx === -1)
            continue; // 标题不存在 → 由 findMissingSections 处理
        const heading = headings[headingIdx];
        // 收集该标题到下一个同级/更高级标题之间的正文
        let bodyChars = 0;
        let inCodeFence = false;
        for (let i = heading.line; i < lines.length; i++) {
            // 检查是否到达下一个同级或更高级标题
            const nextMatch = lines[i].match(/^(#{1,4})\s+/);
            if (nextMatch && i + 1 !== heading.line) {
                // 如果下一个标题的 level <= 当前标题的 level，停止
                if (nextMatch[1].length <= heading.level)
                    break;
            }
            const trimmed = lines[i].trim();
            // 跳过标题行本身
            if (i + 1 === heading.line)
                continue;
            // 跳过空行
            if (trimmed === "")
                continue;
            // 代码围栏状态机 — 跳过整个代码块
            if (trimmed.startsWith("```")) {
                inCodeFence = !inCodeFence;
                continue;
            }
            if (inCodeFence)
                continue;
            // 跳过表格行（header、separator、数据行）
            if (/^\|.*\|$/.test(trimmed))
                continue;
            // 累计正文内容
            bodyChars += trimmed.length;
        }
        if (bodyChars < threshold) {
            results.push({
                section_name: section,
                line_number: heading.line,
                body_chars: bodyChars,
            });
        }
    }
    return results;
}
/**
 * 检测占位符 — 正文中的"待补充"、"TODO"等空洞标记。
 *
 * 维护代码围栏状态机，跳过代码块内行，避免误报。
 * 可追加自定义占位符模式。
 */
export function findPlaceholders(content, extraPatterns) {
    const patterns = [...BUILTIN_PLACEHOLDER_PATTERNS, ...(extraPatterns ?? [])];
    const lines = content.split("\n");
    const results = [];
    let inCodeFence = false;
    for (let i = 0; i < lines.length; i++) {
        const line = lines[i];
        // 代码围栏状态机
        if (line.trim().startsWith("```")) {
            inCodeFence = !inCodeFence;
            continue;
        }
        if (inCodeFence)
            continue;
        // 跳过 markdown 标题行和表格 header 行
        if (/^#{1,4}\s/.test(line))
            continue;
        if (/^\|[-:\s|]+\|$/.test(line))
            continue;
        // 匹配占位符
        for (const pattern of patterns) {
            if (pattern.test(line)) {
                results.push({
                    placeholder: pattern.source,
                    line_number: i + 1,
                    context: line.trim().slice(0, 80),
                });
                break; // 每行只报告第一个匹配
            }
        }
    }
    return results;
}
/**
 * 检测空表格 — 表格有 header 和 separator 但无数据行。
 *
 * 与 schema.required_tables 做关键词匹配，必填表格空 → is_required=true。
 */
export function findEmptyTables(content, schema) {
    const results = [];
    if (!content.includes("|"))
        return results;
    const lines = content.split("\n");
    for (let i = 0; i < lines.length - 1; i++) {
        // 识别表格区域：当前行是 header（含 | 且非 separator），下一行是 separator
        const headerLine = lines[i];
        const nextLine = lines[i + 1] ?? "";
        // 检查是否为 markdown 表格的 header + separator 组合
        if (!/^\|.+\|$/.test(headerLine.trim()))
            continue;
        if (!/^\|[-:\s|]+\|$/.test(nextLine.trim()))
            continue;
        // 收集表格数据行
        let hasDataRows = false;
        for (let j = i + 2; j < lines.length; j++) {
            const rowLine = lines[j].trim();
            // 表格结束
            if (!rowLine.startsWith("|") || rowLine === "")
                break;
            // separator 行跳过（某些格式有多个 separator）
            if (/^\|[-:\s|]+\|$/.test(rowLine))
                continue;
            // 有数据行
            hasDataRows = true;
            break;
        }
        if (!hasDataRows) {
            // 提取表格 header 中的关键词
            const headerCells = headerLine
                .split("|")
                .map((c) => c.trim())
                .filter(Boolean);
            // 与 schema.required_tables 匹配 — 双向部分匹配
            let matchedTable = "";
            let isRequired = false;
            for (const table of schema.required_tables) {
                // 策略 1：schema 表名关键词（去掉"表"后缀）出现在 header 行中
                const tableKeyword = table.replace(/表$/, "");
                const tableShort = tableKeyword.slice(0, 4);
                const escaped = escapeRegExp(tableShort);
                const regex = new RegExp(escaped, "i");
                if (regex.test(headerLine)) {
                    matchedTable = table;
                    isRequired = true;
                    break;
                }
                // 策略 2：header cells 的组合内容包含 schema 表名的核心词
                const headerText = headerCells.join("");
                if (regex.test(headerText)) {
                    matchedTable = table;
                    isRequired = true;
                    break;
                }
                // 策略 3：schema 表名完全匹配 header 行中的某段文本
                if (headerLine.includes(tableKeyword) || headerLine.includes(table)) {
                    matchedTable = table;
                    isRequired = true;
                    break;
                }
            }
            // 即使不是必填表格，也报告为非必填空表格
            if (!matchedTable) {
                matchedTable = headerCells.join("、").slice(0, 30);
            }
            results.push({
                table_keyword: matchedTable,
                line_number: i + 1,
                is_required: isRequired,
            });
        }
    }
    return results;
}
// ── 内部工具 ──
function escapeRegExp(str) {
    return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
//# sourceMappingURL=artifact_schema_registry.js.map