import fs from "node:fs";
import pathModule from "node:path";
import { debug } from "../core/logger.js";
// ── P0 资产清单 ──
/** P0 资产清单 — 所有 P0 优先级的可消费资产 */
export const ASSET_MANIFEST = [
    // mc-intent-router
    { asset_id: "dl-rule-意图路由规则", path: "templates/internal/rules/意图路由规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-intent-router", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-意图路由流程", path: "templates/procedures/意图路由流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-intent-router", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-意图路由流程", path: "templates/procedures/意图路由流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-intent-router", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-workflow-contract
    { asset_id: "dl-rule-工作流契约规则", path: "templates/internal/rules/工作流契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-workflow-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "checklist-工作流验收清单", path: "templates/checklists/工作流验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-workflow-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-checklist-工作流验收清单", path: "templates/checklists/工作流验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-workflow-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-knowledge-injection-boundary
    { asset_id: "dl-rule-知识注入边界规则", path: "templates/internal/rules/知识注入边界规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-knowledge-injection-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "checklist-知识注入验收清单", path: "templates/checklists/知识注入验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-knowledge-injection-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-checklist-知识注入验收清单", path: "templates/checklists/知识注入验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-knowledge-injection-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-tool-invocation-contract
    { asset_id: "dl-rule-工具调用规则", path: "templates/internal/rules/工具调用规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-tool-invocation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "proc-工具调用流程", path: "templates/procedures/工具调用流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-tool-invocation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-proc-工具调用流程", path: "templates/procedures/工具调用流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-tool-invocation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-verifier
    { asset_id: "dl-rule-验证契约规则", path: "templates/internal/rules/验证契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-verifier", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "checklist-验证验收清单", path: "templates/checklists/验证验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-verifier", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-checklist-验证验收清单", path: "templates/checklists/验证验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-verifier", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-main-path-integration
    { asset_id: "dl-rule-防孤岛实现规则", path: "templates/internal/rules/防孤岛实现规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-main-path-integration", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "proc-主链路接入验证流程", path: "templates/procedures/主链路接入验证流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-main-path-integration", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-主链路接入验证流程", path: "templates/procedures/主链路接入验证流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-main-path-integration", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "checklist-主链路接入验收清单", path: "templates/checklists/主链路接入验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-main-path-integration", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-checklist-主链路接入验收清单", path: "templates/checklists/主链路接入验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-main-path-integration", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-privacy-boundary
    { asset_id: "dl-rule-敏感信息处理规则", path: "templates/internal/rules/敏感信息处理规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-privacy-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "checklist-隐私审查清单", path: "templates/checklists/隐私审查清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-privacy-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-checklist-隐私审查清单", path: "templates/checklists/隐私审查清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-privacy-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-command-execution
    { asset_id: "dl-rule-命令执行规则", path: "templates/internal/rules/命令执行规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-command-execution", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "proc-命令执行流程", path: "templates/procedures/命令执行流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-command-execution", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-proc-命令执行流程", path: "templates/procedures/命令执行流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-command-execution", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-core-engineering-principles
    { asset_id: "dl-rule-核心工程执行原则", path: "templates/internal/rules/核心工程执行原则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-core-engineering-principles", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-checklist-核心工程执行验收清单", path: "templates/checklists/核心工程执行验收清单.md", asset_kind: "checklist", owner_mechanism_id: "mc-core-engineering-principles", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-proc-编码前澄清流程", path: "templates/procedures/编码前澄清流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-core-engineering-principles", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-delivery-gate
    { asset_id: "proc-验收测试规划", path: "templates/procedures/验收测试规划.md", asset_kind: "procedure", owner_mechanism_id: "mc-verifier", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-guard-evaluation
    { asset_id: "dl-rule-执行守卫评估规则", path: "templates/internal/rules/执行守卫评估规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-guard-evaluation", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-registry-infrastructure
    { asset_id: "dl-rule-注册表基础设施规则", path: "templates/internal/rules/注册表基础设施规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-registry-infrastructure", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-artifact-contract
    { asset_id: "dl-rule-产物契约规则", path: "templates/internal/rules/产物契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-artifact-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-验收模版输出契约规则", path: "templates/internal/rules/验收模版输出契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-standard-asset-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-通用决策研讨规则", path: "templates/internal/rules/通用决策研讨规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-decision-workshop", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-标准资产覆盖规则", path: "templates/internal/rules/标准资产覆盖规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-standard-asset-coverage", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-模版资产可见性规则", path: "templates/internal/rules/模版资产可见性规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-template-asset-visibility", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-工作流导航契约规则", path: "templates/internal/rules/工作流导航契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-workflow-navigation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-全生命周期工作流导航", path: "templates/procedures/全生命周期工作流导航.md", asset_kind: "procedure", owner_mechanism_id: "mc-workflow-navigation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-OOD与SOLID设计规则", path: "templates/internal/rules/OOD与SOLID设计规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-ood-solid-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-OOD设计工作流", path: "templates/procedures/OOD设计工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-ood-solid-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-review-SOLID代码审查规则", path: "templates/rules/shared/SOLID代码审查规则.md", asset_kind: "review_rule", owner_mechanism_id: "mc-ood-solid-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-accept-OOD设计摘要模版", path: "templates/artifacts/shared/OOD设计摘要模版.md", asset_kind: "acceptance_template", owner_mechanism_id: "mc-ood-solid-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-pattern-SOLID设计规范", path: "templates/patterns/SOLID设计规范.md", asset_kind: "global_pattern", owner_mechanism_id: "mc-ood-solid-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-rule-后端实现工程契约规则", path: "templates/internal/rules/后端实现工程契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-backend-implementation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-后端接口实现工作流", path: "templates/procedures/后端接口实现工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-backend-implementation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-review-后端实现工程审查规则", path: "templates/rules/shared/后端实现工程审查规则.md", asset_kind: "review_rule", owner_mechanism_id: "mc-backend-implementation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-accept-后端实现验收清单", path: "templates/artifacts/shared/后端实现验收清单.md", asset_kind: "acceptance_template", owner_mechanism_id: "mc-backend-implementation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-pattern-后端实现工程规范", path: "templates/patterns/后端实现工程规范.md", asset_kind: "global_pattern", owner_mechanism_id: "mc-backend-implementation-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-user-feedback
    { asset_id: "dl-rule-用户反馈契约规则", path: "templates/internal/rules/用户反馈契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-user-feedback", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-config-precedence
    { asset_id: "dl-rule-配置优先级规则", path: "templates/internal/rules/配置优先级规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-config-precedence", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-zero-config-init
    { asset_id: "dl-rule-零配置初始化规则", path: "templates/internal/rules/零配置初始化规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-zero-config-init", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-input-material-contract
    { asset_id: "dl-rule-输入材料契约规则", path: "templates/internal/rules/输入材料契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-input-material-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // ── 辅助治理资产（反向覆盖） ──
    { asset_id: "proc-Schema变更流水线", path: "templates/procedures/Schema变更流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-knowledge-asset-governance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-代码门禁流程", path: "templates/procedures/代码门禁流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-guard-evaluation", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-任务拆解流程", path: "templates/procedures/任务拆解流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-intent-expander", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-功能开发流程", path: "templates/procedures/功能开发流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-task-context-lifecycle", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-安全加固流水线", path: "templates/procedures/安全加固流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-privacy-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-性能流水线", path: "templates/procedures/性能流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-metric-governance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-接口集成流水线", path: "templates/procedures/接口集成流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-artifact-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-数据库迁移流程", path: "templates/procedures/数据库迁移流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-knowledge-asset-governance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-架构设计工作流", path: "templates/procedures/架构设计工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-architecture-design", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-概念验证流水线", path: "templates/procedures/概念验证流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-brainstorm-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-源码原型交付流程", path: "templates/procedures/源码原型交付流程.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-artifact-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-知识维护流水线", path: "templates/procedures/知识维护流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-knowledge-injection-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-紧急修复流水线", path: "templates/procedures/紧急修复流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-delivery-gate", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-调试排查流程", path: "templates/procedures/调试排查流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-verifier", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-自主选型流程", path: "templates/procedures/自主选型流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-decision-sovereignty", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-详细设计流程", path: "templates/procedures/详细设计流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-architecture-design", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-迁移流水线", path: "templates/procedures/迁移流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-knowledge-asset-governance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-部署发布流程", path: "templates/procedures/部署发布流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-delivery-gate", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-重构流水线", path: "templates/procedures/重构流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-task-context-lifecycle", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-集成验证流程", path: "templates/procedures/集成验证流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-verifier", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "proc-需求澄清流程", path: "templates/procedures/需求澄清流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-intent-router", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-rule-核心体验原则", path: "templates/internal/rules/核心体验原则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-core-experience-principle", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-验收测试规划", path: "templates/procedures/验收测试规划.md", asset_kind: "procedure", owner_mechanism_id: "mc-delivery-gate", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-现有系统差距分析工作流", path: "templates/procedures/现有系统差距分析工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-existing-system-analysis", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "proc-现有系统差距分析工作流", path: "templates/procedures/现有系统差距分析工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-existing-system-analysis", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-执行守卫评估规则-required", path: "templates/internal/rules/执行守卫评估规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-guard-evaluation", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-知识资产治理规则", path: "templates/internal/rules/知识资产治理规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-knowledge-asset-governance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-本地浏览器验收工作流", path: "templates/procedures/本地浏览器验收工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-local-acceptance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "proc-本地浏览器验收工作流", path: "templates/procedures/本地浏览器验收工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-local-acceptance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-计划前置门规则", path: "templates/internal/rules/计划前置门规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-plan-proposal-gate", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-架构设计工作流", path: "templates/procedures/架构设计工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-architecture-design", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-架构决策研讨规则", path: "templates/internal/rules/架构决策研讨规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-architecture-decision-workshop", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-架构决策研讨工作流", path: "templates/procedures/架构决策研讨工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-architecture-decision-workshop", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "proc-架构决策研讨工作流", path: "templates/procedures/架构决策研讨工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-architecture-decision-workshop", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-rule-设计产物包规则", path: "templates/internal/rules/设计产物包规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-design-artifact-pack", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-设计产物生成与复验工作流", path: "templates/procedures/设计产物生成与复验工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-design-artifact-pack", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "proc-设计产物生成与复验工作流", path: "templates/procedures/设计产物生成与复验工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-design-artifact-pack", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "dl-proc-测试优先编码工作流", path: "templates/procedures/测试优先编码工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-coding-readiness", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "proc-测试优先编码工作流", path: "templates/procedures/测试优先编码工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-coding-readiness", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // ── 双层机制 required 模板资产 ──
    // mc-task-context-lifecycle
    { asset_id: "dl-rule-任务上下文生命周期规则", path: "templates/internal/rules/任务上下文生命周期规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-task-context-lifecycle", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-decision-sovereignty
    { asset_id: "dl-rule-技术决策主权规则", path: "templates/internal/rules/技术决策主权规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-decision-sovereignty", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-架构设计工作流-mc-decision-sovereignty", path: "templates/procedures/架构设计工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-decision-sovereignty", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-brainstorm-contract
    { asset_id: "dl-rule-脑暴与方案探索规则", path: "templates/internal/rules/脑暴与方案探索规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-brainstorm-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-架构设计工作流-mc-brainstorm-contract", path: "templates/procedures/架构设计工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-brainstorm-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-detail-discipline
    { asset_id: "dl-rule-细节纪律规则", path: "templates/internal/rules/细节纪律规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-detail-discipline", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-测试优先编码工作流-mc-detail-discipline", path: "templates/procedures/测试优先编码工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-detail-discipline", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-first-principles
    { asset_id: "dl-rule-第一性原理推理规则", path: "templates/internal/rules/第一性原理推理规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-first-principles", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-proc-架构设计工作流-mc-first-principles", path: "templates/procedures/架构设计工作流.md", asset_kind: "procedure", owner_mechanism_id: "mc-first-principles", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // mc-evolution-regression
    { asset_id: "dl-rule-演进回归门控规则", path: "templates/internal/rules/演进回归门控规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-evolution-regression", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-extension-contract
    { asset_id: "dl-rule-扩展生命周期规则", path: "templates/internal/rules/扩展生命周期规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-extension-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-platform-compatibility
    { asset_id: "dl-rule-跨平台路径安全规则", path: "templates/internal/rules/跨平台路径安全规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-platform-compatibility", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-workflow-template-pack
    { asset_id: "dl-rule-工作流模版包规则", path: "templates/internal/rules/工作流模版包规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-workflow-template-pack", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-intent-expander (required template)
    { asset_id: "dl-proc-任务拆解流程-mc-intent-expander", path: "templates/procedures/任务拆解流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-intent-expander", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-metric-governance (required template)
    { asset_id: "dl-proc-性能流水线-mc-metric-governance", path: "templates/procedures/性能流水线.md", asset_kind: "pipeline_procedure", owner_mechanism_id: "mc-metric-governance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-instruction-contract (required template)
    { asset_id: "dl-rule-施工指令契约规则", path: "templates/internal/rules/施工指令契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-instruction-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-evidence-grounding (required template)
    { asset_id: "dl-rule-证据驱动与反幻觉规则", path: "templates/internal/rules/证据驱动与反幻觉规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-evidence-grounding", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // 长期机制化治理
    { asset_id: "dl-rule-机制自治理规则", path: "templates/internal/rules/机制自治理规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-mechanism-health", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-配置落盘边界规则", path: "templates/internal/rules/配置落盘边界规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-config-write-boundary", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-知识治理规则", path: "templates/internal/rules/知识治理规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-knowledge-governance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-rule-日志治理规则", path: "templates/internal/rules/日志治理规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-log-governance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    // mc-code-maintainability-observability-contract
    { asset_id: "dl-rule-代码注释与日志契约规则", path: "templates/internal/rules/代码注释与日志契约规则.md", asset_kind: "governance_rule", owner_mechanism_id: "mc-code-maintainability-observability-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-review-代码可维护性与可观测性审查", path: "templates/rules/shared/代码可维护性与可观测性审查.md", asset_kind: "review_rule", owner_mechanism_id: "mc-code-maintainability-observability-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "required" },
    { asset_id: "dl-accept-代码注释与日志验收模版", path: "templates/artifacts/shared/代码注释与日志验收模版.md", asset_kind: "acceptance_template", owner_mechanism_id: "mc-code-maintainability-observability-contract", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // ── P1 补充资产：8 Gate + 1 Procedure + 5 Review Rule ──
    // 8 个阶段门禁（shared）
    { asset_id: "pipe-shared-gate-gate-会话启动", path: "templates/gates/shared/gate-会话启动.yaml", asset_kind: "stage_gate", owner_mechanism_id: "mc-stage-gate-engine", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "copy_only" },
    { asset_id: "pipe-shared-gate-gate-决策研讨", path: "templates/gates/shared/gate-决策研讨.yaml", asset_kind: "stage_gate", owner_mechanism_id: "mc-stage-gate-engine", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "copy_only" },
    { asset_id: "pipe-shared-gate-gate-编码准备", path: "templates/gates/shared/gate-编码准备.yaml", asset_kind: "stage_gate", owner_mechanism_id: "mc-stage-gate-engine", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "copy_only" },
    { asset_id: "pipe-shared-gate-gate-编码实现", path: "templates/gates/shared/gate-编码实现.yaml", asset_kind: "stage_gate", owner_mechanism_id: "mc-stage-gate-engine", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "copy_only" },
    { asset_id: "pipe-shared-gate-gate-编码验证", path: "templates/gates/shared/gate-编码验证.yaml", asset_kind: "stage_gate", owner_mechanism_id: "mc-stage-gate-engine", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "copy_only" },
    { asset_id: "pipe-shared-gate-gate-本地验收", path: "templates/gates/shared/gate-本地验收.yaml", asset_kind: "stage_gate", owner_mechanism_id: "mc-stage-gate-engine", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "copy_only" },
    { asset_id: "pipe-shared-gate-gate-交付", path: "templates/gates/shared/gate-交付.yaml", asset_kind: "stage_gate", owner_mechanism_id: "mc-stage-gate-engine", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "copy_only" },
    { asset_id: "pipe-shared-gate-gate-发布后观察", path: "templates/gates/shared/gate-发布后观察.yaml", asset_kind: "stage_gate", owner_mechanism_id: "mc-stage-gate-engine", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "copy_only" },
    // 1 个共享流程
    { asset_id: "ka-procedure-会话恢复流程", path: "templates/procedures/会话恢复流程.md", asset_kind: "procedure", owner_mechanism_id: "mc-session-recovery", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    // 5 个审查规则
    { asset_id: "ka-review-rule-需求质量审查规则", path: "templates/rules/shared/需求质量审查规则.md", asset_kind: "review_rule", owner_mechanism_id: "mc-intent-router", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "ka-review-rule-决策完整性审查规则", path: "templates/rules/shared/决策完整性审查规则.md", asset_kind: "review_rule", owner_mechanism_id: "mc-architecture-decision-workshop", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "ka-review-rule-编码就绪审查规则", path: "templates/rules/shared/编码就绪审查规则.md", asset_kind: "review_rule", owner_mechanism_id: "mc-coding-readiness", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "ka-review-rule-验收标准审查规则", path: "templates/rules/shared/验收标准审查规则.md", asset_kind: "review_rule", owner_mechanism_id: "mc-local-acceptance", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
    { asset_id: "ka-review-rule-发布后审查规则", path: "templates/rules/shared/发布后审查规则.md", asset_kind: "review_rule", owner_mechanism_id: "mc-delivery-gate", enforcement_status: "enforced", layer_status: "dual_layer_enforced", consumption_mode: "supporting" },
];
// ── 工作流模板硬规则清单（结构化真源） ──
/**
 * 工作流模板硬规则清单 — 这是唯一的真源。
 * generateWorkflowRules() 从此清单生成用户可见文本和标记。
 * adapter 与 asset_manifest 共用同一结构化来源。
 */
export const WORKFLOW_TEMPLATE_HARD_RULES = [
    { rule_id: "wf-classify-first", rule_summary: "sf_classify 必须在 sf_expand 之前调用", user_instruction: "调用 `sf_classify` 分类。", mechanism_id: "mc-workflow-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-classify-first" },
    { rule_id: "wf-strategy-no-route", rule_summary: "strategy 字段不得用作实际路由决策", user_instruction: "`strategy` 仅兼容展示，不作为入口裁决。", mechanism_id: "mc-workflow-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-strategy-no-route" },
    { rule_id: "wf-routing-gate", rule_summary: "入口裁决: skip_chat/missing_inputs/review/multi_stage_plan 路由硬约束", user_instruction: "按分类结果 `route_decision` 字段分发。详见知识库路由规则。", mechanism_id: "mc-workflow-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-routing-gate" },
    { rule_id: "wf-multi-stage-loop", rule_summary: "多阶段循环: sf_expand→执行→sf_plan_advance→重复", user_instruction: "`execution_shape=multi_stage_plan` 时: `sf_plan` → `sf_expand` → 执行 → `sf_plan_advance` → 循环。", mechanism_id: "mc-workflow-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-multi-stage-loop" },
    { rule_id: "wf-dispatch-by-route", rule_summary: "route=operation/verification_only 不得默认 sf_expand; scaffold 必须先 sf_scaffold", user_instruction: "按分类结果调用对应工具。详见知识库流程。", mechanism_id: "mc-workflow-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-dispatch-by-route" },
    { rule_id: "wf-verify-after-change", rule_summary: "代码修改后必须 sf_verify 并通过 Bash 执行验证命令", user_instruction: "代码修改后调用 `sf_verify` 并执行返回的验证命令。", mechanism_id: "mc-verifier", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-verify-after-change" },
    { rule_id: "wf-learn-after-verify", rule_summary: "验证完成后必须 sf_learn; retry_hint 时回到步骤 3", user_instruction: "验证后调用 `sf_learn`。若有 `retry_hint` 回到步骤 3。", mechanism_id: "mc-task-context-lifecycle", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-learn-after-verify" },
    { rule_id: "wf-no-auto-capability-change", rule_summary: "能力状态不自动变更; 状态更新必须确认+证据; 仅记录不自动执行", user_instruction: "能力状态不自动变更。状态更新必须经用户确认并附证据。仅记录不自动执行。", mechanism_id: "mc-guard-evaluation", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-no-auto-capability-change" },
    { rule_id: "wf-privacy-before-expand", rule_summary: "隐私门禁必须在 sf_expand 之前执行", user_instruction: "隐私门禁必须在 `sf_expand` 之前执行。", mechanism_id: "mc-privacy-boundary", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-privacy-before-expand" },
    { rule_id: "wf-command-contract", rule_summary: "命令执行必须通过 command_execution_contract 校验", user_instruction: "命令执行必须通过 `command_execution_contract` 校验。", mechanism_id: "mc-command-execution", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-command-contract" },
    { rule_id: "wf-tool-contract", rule_summary: "工具调用必须通过 tool_invocation_contract 校验", user_instruction: "工具调用必须通过 `tool_invocation_contract` 校验。", mechanism_id: "mc-tool-invocation-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-tool-contract" },
    { rule_id: "wf-core-principles", rule_summary: "必须查阅知识库注入的核心工程执行原则", user_instruction: "必须查阅知识库注入的核心工程执行原则。", mechanism_id: "mc-core-engineering-principles", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-core-principles" },
    { rule_id: "wf-knowledge-injection", rule_summary: "必须通过知识注入边界机制注入匹配的机制知识资产", user_instruction: "必须通过知识注入边界机制注入匹配的机制知识资产。", mechanism_id: "mc-knowledge-injection-boundary", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-knowledge-injection" },
    { rule_id: "wf-evidence-grounding", rule_summary: "关键事实和交付结论必须有 evidence_refs，证据不足必须说明不确定并请求确认", user_instruction: "关键事实和交付结论必须有 evidence_refs，证据不足时必须说明不确定并请求确认。验证计划不得当作验证结果。", mechanism_id: "mc-evidence-grounding", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-evidence-grounding" },
    { rule_id: "wf-architecture-workshop-first", rule_summary: "架构设计前必须完成六类决策研讨与用户确认", user_instruction: "涉及架构设计时，必须先完成业务流程、数据、安全、后端、前端、基础设施六类决策研讨与用户确认，再生成正式设计产物。", mechanism_id: "mc-architecture-decision-workshop", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-architecture-workshop-first" },
    { rule_id: "wf-design-artifact-pack", rule_summary: "设计产物必须经过真实产物包复验后才能用于编码或交付", user_instruction: "涉及架构、数据库或 API 设计产物时，必须按设计产物包规则生成或升级；未经真实复验的旧文档不得用于编码结论。", mechanism_id: "mc-design-artifact-pack", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-design-artifact-pack" },
    { rule_id: "wf-standard-asset-contract", rule_summary: "正式输出产物必须按标准资产契约验收后才能进入编码或交付", user_instruction: "涉及模板、规则、流程、检查清单、审查规则、模式、脚手架或 adapter workflow 的正式输出产物，必须按标准资产契约验收后才能进入编码或交付；验收失败必须修复重验。", mechanism_id: "mc-standard-asset-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-standard-asset-contract" },
    { rule_id: "wf-template-asset-visibility", rule_summary: "内部治理资产不得同步到用户项目，不同技术栈审查规则不得互相注入", user_instruction: "内部治理资产不得同步到用户项目知识库，不同技术栈的审查规则不得互相注入，脚手架模板只由脚手架机制消费。", mechanism_id: "mc-template-asset-visibility", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-template-asset-visibility" },
    { rule_id: "wf-navigation-contract", rule_summary: "模糊推进意图和阻断恢复必须先调用阶段导航，不得绕过 SoloForge 状态", user_instruction: "用户说\"下一步\"\"继续\"\"现在能写代码吗\"等模糊推进语义时，必须先调用 sf_navigation 或 soloforge next 查询阶段导航，不得靠模型经验回答。SoloForge 阻断 Edit/Write/Bash 时，不得建议取消任务后直接写、先用 Bash 写、手动清理状态或先实现后补验证；只能按 tool 返回的 recovery_command、soloforge next、sf_expand、sf_verify 或经确认的 sf_status archive_stale 恢复，归档陈旧任务也不是直接写代码许可。", mechanism_id: "mc-workflow-navigation-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-navigation-contract" },
    { rule_id: "wf-code-observability", rule_summary: "业务编码必须满足必要注释与日志契约；敏感信息泄漏、catch 吞异常、关键操作无日志必须阻断", user_instruction: "业务编码、接口实现、支付、权限、状态变更、数据修复等关键路径必须有结构化日志和必要注释；敏感信息不得进入日志；catch 块不得吞异常；简单低风险改动不强制。", mechanism_id: "mc-code-maintainability-observability-contract", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-code-observability" },
    { rule_id: "wf-no-lazy-code", rule_summary: "代码产物不得包含偷懒模式（空函数体/TODO/空 catch/未实现占位/空洞章节）", user_instruction: "写入代码时不得留空函数体、TODO 注释、空 catch 块、not implemented 占位。写入设计文档时不得留空洞章节、占位符、空表格。check-write Hook 会自动拦截；无 Hook 的适配器在 sf_verify 阶段检测。", mechanism_id: "mc-code-quality-gate", enforcement_status: "enforced", source_ref: "src/adapters/shared/workflow_template.ts#wf-no-lazy-code" },
];
// ── 三方对账 ──
/** 三方对账: 清单 <-> 文件系统 <-> 可消费资产注册表
 * @param manifest - P0 资产清单
 * @param assetPaths - 已注册资产路径集合
 * @param assetById - 按 asset_id 索引的注册资产映射
 * @param rootDir - 项目根目录
 * @param assetByPath - 按路径索引的资产 ID 映射 (可选)
 * @returns 治理发现列表
 */
export function reconcileManifest(manifest, assetPaths, assetById, rootDir, assetByPath) {
    debug("资产清单", "开始三方对账，共 %d 条资产", manifest.length);
    const findings = [];
    for (const entry of manifest) {
        // 1. 文件存在
        if (!fs.existsSync(pathModule.join(rootDir, entry.path))) {
            findings.push({
                severity: "hard_fail",
                finding_type: "manifest_file_missing",
                subject: entry.asset_id,
                message: `Manifest 资产文件不存在: ${entry.path}`,
            });
        }
        // 2. 在 Consumable Asset Registry 中注册
        if (!assetPaths.has(entry.path)) {
            findings.push({
                severity: "hard_fail",
                finding_type: "unregistered_hard_rule",
                subject: entry.asset_id,
                message: `Manifest 资产 ${entry.path} 未在 Consumable Asset Registry 中注册`,
            });
        }
        // 3. owner_mechanism_id 一致性（按 id）
        const regAsset = assetById.get(entry.asset_id);
        if (regAsset && regAsset.owner_mechanism_id !== entry.owner_mechanism_id) {
            findings.push({
                severity: "hard_fail",
                finding_type: "workflow_template_drift",
                subject: entry.asset_id,
                message: `Manifest owner=${entry.owner_mechanism_id} vs Registry owner=${regAsset.owner_mechanism_id}`,
            });
        }
        // 4. asset_id 对齐: manifest asset_id 必须与同路径的至少一个 registry id 匹配
        if (assetByPath) {
            const pathAssets = assetByPath.get(entry.path);
            if (pathAssets && !pathAssets.includes(entry.asset_id)) {
                findings.push({
                    severity: "hard_fail",
                    finding_type: "asset_id_mismatch",
                    subject: entry.asset_id,
                    message: `Manifest asset_id=${entry.asset_id} 与 Registry ids=[${pathAssets.join(",")}] 均不一致（path=${entry.path}）`,
                });
            }
        }
    }
    if (findings.length > 0) {
        debug("资产清单", "三方对账发现 %d 个问题", findings.length);
    }
    else {
        debug("资产清单", "三方对账通过");
    }
    if (findings.length > 0) {
        debug("资产清单", "反向覆盖检查发现 %d 个问题", findings.length);
    }
    return findings;
}
// ── 反向覆盖: 注册表 → 清单 ──
/** 反向覆盖检查: 注册表 -> 清单，确保无遗漏资产
 * @param manifest - P0 资产清单
 * @param allAssets - 所有可消费资产引用列表
 * @param knownMechanismIds - 已知机制 ID 集合 (可选)
 * @returns 治理发现列表
 */
export function checkManifestReverseCoverage(manifest, allAssets, _knownMechanismIds) {
    debug("资产清单", "开始反向覆盖检查，共 %d 条清单资产, %d 条注册资产", manifest.length, allAssets.length);
    const findings = [];
    const manifestIds = new Set(manifest.map((e) => e.asset_id));
    // 检查 manifest 中已有机制所需的 required 和 supporting 治理资产
    const manifestMechanisms = new Set(manifest.map((e) => e.owner_mechanism_id));
    const GOVERNANCE_ASSET_KINDS = ["governance_rule", "procedure", "checklist"];
    const COVERED_MODES = ["required", "supporting"];
    for (const asset of allAssets) {
        if (COVERED_MODES.includes(asset.consumption_mode) &&
            asset.owner_mechanism_id &&
            manifestMechanisms.has(asset.owner_mechanism_id) &&
            GOVERNANCE_ASSET_KINDS.includes(asset.asset_kind) &&
            !manifestIds.has(asset.id)) {
            findings.push({
                severity: "hard_fail",
                finding_type: "unregistered_manifest_asset",
                subject: asset.id,
                message: `Consumable Asset Registry 中有 P0 ${asset.consumption_mode} 治理资产 ${asset.id} (${asset.owner_mechanism_id}) 但未在 ASSET_MANIFEST 中登记`,
            });
        }
    }
    // asset_id 对齐检查: manifest 条目 id 必须匹配 registry id 和 path
    const assetById = new Map(allAssets.map((a) => [a.id, a]));
    for (const entry of manifest) {
        const regAsset = assetById.get(entry.asset_id);
        if (regAsset && regAsset.path !== entry.path) {
            findings.push({
                severity: "hard_fail",
                finding_type: "asset_id_path_mismatch",
                subject: entry.asset_id,
                message: `Manifest asset_id=${entry.asset_id} path=${entry.path} 与 Registry path=${regAsset.path} 不一致`,
            });
        }
    }
    return findings;
}
//# sourceMappingURL=asset_manifest.js.map