/**
 * Mechanism Contract Registry — 审计与管线架构机制契约（管道核心 + 审计补注册）。
 *
 * 管道核心：stage_gate_engine、rollback_router、slice_executor。
 * 审计补注册：code_review、design_lifecycle、api_contract_guard、diff_ownership、
 * llm_gateway、template_mechanism_audit、scope_control、runtime_safety、
 * diagnostic_code_contract、contract_state_lifecycle、tech_debt_lifecycle、
 * change_coordination、test_quality_assurance、config_auto_repair。
 */
/** 管道核心 + 审计补注册 P0 机制契约 */
export const AUDIT_CONTRACTS = [
    // ══════════════════════════════════════════════════
    // 管线核心机制（工作流管线架构新增）
    // ══════════════════════════════════════════════════
    // ── 门禁引擎 ──
    {
        id: "mc-stage-gate-engine",
        name: "门禁引擎",
        owner_module: "src/engine/pipeline/stage_gate_engine.ts",
        owner_exports: ["executeStageGate", "loadGateConfig"],
        mechanism_type: "governance",
        status: "enforced",
        trigger: "每个管线阶段执行前",
        required_inputs: ["当前阶段", "gate配置(YAML)", "待校验产物"],
        preconditions: ["gate配置文件存在"],
        outputs: ["GateCheckResult"],
        downstream_consumers: ["管线执行器", "阶段契约"],
        failure_modes: ["门禁配置缺失", "校验产物不完整"],
        degradation_behavior: "缺失配置时 advisory 不阻断",
        tests: ["tests/engine/design_lifecycle_contract.test.ts"],
        lifecycle_tests: ["tests/engine/design_lifecycle_contract.test.ts"],
    },
    // ── 回退路由 ──
    {
        id: "mc-rollback-router",
        name: "回退路由",
        owner_module: "src/engine/pipeline/rollback_router.ts",
        owner_exports: ["resolveRollbackTarget", "executeRollback"],
        mechanism_type: "state_lifecycle",
        status: "enforced",
        trigger: "阶段执行失败或门禁阻断时",
        required_inputs: ["当前阶段", "回退类型", "回退原因"],
        preconditions: ["存在可回退的上游阶段"],
        outputs: ["RollbackTarget", "回退指令"],
        downstream_consumers: ["管线执行器", "阶段契约"],
        state_transitions: [
            "详细设计 → 需求分析",
            "编码与单元测试 → 详细设计",
            "联调验证 → 架构设计",
            "现有系统分析 → 需求分析",
            "编码与单元测试 → 架构设计",
            "联调验证 → 编码与单元测试",
        ],
        failure_modes: ["回退目标不存在", "回退循环"],
        degradation_behavior: "无可用回退路径时 stop_escalate",
        tests: ["tests/engine/design_lifecycle_contract.test.ts"],
        lifecycle_tests: ["tests/engine/design_lifecycle_contract.test.ts"],
    },
    // ── 切片执行器 ──
    {
        id: "mc-slice-executor",
        name: "切片执行器",
        owner_module: "src/engine/pipeline/slice_executor.ts",
        owner_exports: ["createSliceContext", "reviewSlice", "getNextSlice"],
        mechanism_type: "planning",
        status: "enforced",
        trigger: "编码与单元测试阶段执行时",
        required_inputs: ["切片计划", "已通过切片列表"],
        preconditions: ["切片计划已生成"],
        outputs: ["SliceExecutionResult", "SliceReviewResult"],
        downstream_consumers: ["编码阶段", "代码审查阶段"],
        failure_modes: ["切片间隔离违反", "切片依赖循环"],
        degradation_behavior: "隔离违反时阻断当前切片",
        tests: ["tests/engine/design_lifecycle_contract.test.ts"],
        lifecycle_tests: ["tests/engine/design_lifecycle_contract.test.ts"],
    },
    // ══════════════════════════════════════════════════
    // 审计补注册：14 个已实现模块注册为正式机制
    // ══════════════════════════════════════════════════
    // ── 代码审查 ──
    {
        id: "mc-code-review",
        name: "代码审查",
        owner_module: "src/engine/audit/code_reviewer.ts",
        owner_exports: ["reviewCode", "renderSummaryBacktrace"],
        mechanism_type: "review",
        status: "enforced",
        trigger: "编码与单元测试完成后、交付前",
        required_inputs: ["changed_files", "task_context"],
        preconditions: ["代码变更已发生"],
        outputs: ["CodeReviewResult"],
        downstream_consumers: ["sf_verify", "sf_deliver", "代码审查阶段"],
        failure_modes: ["审查发现未反馈到管道", "hotfix 跳过审查", "task_id 始终为空"],
        degradation_behavior: "代码审查结果为纯信息性，不阻断后续操作",
        tests: ["tests/engine/code_reviewer.test.ts"],
        lifecycle_tests: ["tests/engine/code_reviewer.test.ts"],
    },
    // ── 设计生命周期契约 ──
    {
        id: "mc-design-lifecycle",
        name: "设计生命周期契约",
        owner_module: "src/engine/contracts/design_lifecycle_contract.ts",
        owner_exports: ["listDesignLifecycleStageContracts", "validateDesignLifecycleContract"],
        mechanism_type: "state_lifecycle",
        status: "enforced",
        trigger: "管线阶段流转时",
        required_inputs: ["stage_id", "artifacts"],
        preconditions: ["项目配置已加载"],
        outputs: ["DesignLifecycleStageContract", "DesignLifecycleContractFinding"],
        downstream_consumers: ["管线执行器", "门禁引擎", "回退路由"],
        state_transitions: [
            "需求分析 → 现有系统分析",
            "现有系统分析 → 架构设计",
            "架构设计 → 详细设计",
            "详细设计 → 任务规划",
            "任务规划 → 编码与单元测试",
            "编码与单元测试 → 代码审查",
            "代码审查 → 联调验证",
        ],
        failure_modes: ["阶段产物不完整", "跳过阶段"],
        degradation_behavior: "阶段产物缺失时报告为 finding",
        tests: ["tests/engine/design_lifecycle_contract.test.ts"],
        lifecycle_tests: ["tests/engine/design_lifecycle_contract.test.ts"],
    },
    // ── API 契约守卫 ──
    {
        id: "mc-api-contract-guard",
        name: "API 契约守卫",
        owner_module: "src/engine/contracts/contract_guard.ts",
        owner_exports: ["checkContractChanges"],
        mechanism_type: "contract_enforcement",
        status: "enforced",
        trigger: "契约文件变更时",
        required_inputs: ["contract_files", "change_context"],
        preconditions: ["契约文件存在"],
        outputs: ["ContractGuardResult"],
        downstream_consumers: ["sf_verify", "sf_deliver"],
        failure_modes: ["契约破坏性变更未检测", "向后兼容性违规"],
        degradation_behavior: "守卫检查不可用时降级为 advisory",
        tests: ["tests/engine/contract_guard.test.ts"],
        lifecycle_tests: ["tests/engine/contract_guard.test.ts"],
    },
    // ── Diff 所有权追踪 ──
    {
        id: "mc-diff-ownership",
        name: "Diff 所有权追踪",
        owner_module: "src/engine/pipeline/diff_ownership.ts",
        owner_exports: ["captureBaseline", "casCheck", "recordTaskWrite", "summarizeOwnership"],
        mechanism_type: "safety",
        status: "enforced",
        trigger: "写入操作前后",
        required_inputs: ["file_path", "task_id"],
        preconditions: ["scope lease 已获取"],
        outputs: ["OwnershipSnapshot", "CasCheckResult", "OwnershipSummary"],
        downstream_consumers: ["sf_expand", "sf_verify", "conflict_gate"],
        failure_modes: ["CAS 校验失败仅 advisory", "taskId 无认证", "store 损坏静默丢弃"],
        degradation_behavior: "CAS 校验失败时产生 advisory 结果，写入始终继续",
        tests: ["tests/engine/diff_ownership.test.ts"],
        lifecycle_tests: ["tests/engine/diff_ownership.test.ts"],
    },
    // ── LLM 网关 ──
    {
        id: "mc-llm-gateway",
        name: "LLM 网关",
        owner_module: "src/engine/core/llm_gateway.ts",
        owner_exports: ["LLMGateway"],
        mechanism_type: "observability",
        status: "enforced",
        trigger: "LLM 调用时",
        required_inputs: ["model_id", "prompt", "budget"],
        preconditions: ["网关已初始化"],
        outputs: ["LLMGatewayResult", "budget_status"],
        downstream_consumers: ["sf_classify", "sf_expand", "sf_verify"],
        failure_modes: ["断路器触发后无自动恢复", "置信度门控依赖调用方诚实", "无操作超时"],
        degradation_behavior: "断路器触发后阻断所有调用，需手动 reset()",
        tests: ["tests/engine/llm_gateway.test.ts"],
        lifecycle_tests: ["tests/engine/llm_gateway.test.ts"],
    },
    // ── 模板机制审计 ──
    {
        id: "mc-template-mechanism-audit",
        name: "模板机制审计",
        owner_module: "src/engine/templates/template_mechanism_auditor.ts",
        owner_exports: ["auditTemplateMechanisms", "isInjectionAllowed"],
        mechanism_type: "governance",
        status: "enforced",
        trigger: "validate-mechanisms 与 validate-release",
        required_inputs: ["rootDir"],
        preconditions: ["模板目录存在"],
        outputs: ["TemplateMechanismAuditReport"],
        downstream_consumers: ["validate-mechanisms", "validate-release"],
        failure_modes: ["模板与机制不匹配", "注入规则不一致"],
        degradation_behavior: "审计失败时报告 finding，不阻断",
        tests: ["tests/engine/foundation_dual_layer.test.ts"],
        lifecycle_tests: ["tests/engine/foundation_dual_layer.test.ts"],
    },
    // ── Scope 控制 ──
    {
        id: "mc-scope-control",
        name: "范围控制器",
        owner_module: "src/engine/pipeline/scope_controller.ts",
        owner_exports: ["checkScope"],
        mechanism_type: "safety",
        status: "enforced",
        trigger: "文件操作前",
        required_inputs: ["file_path", "allowed_paths"],
        preconditions: ["scope 已定义"],
        outputs: ["ScopeCheckResult"],
        downstream_consumers: ["sf_expand", "sf_verify", "diff_ownership"],
        failure_modes: ["Gitleaks 结果被丢弃", "scope 边界绕过"],
        degradation_behavior: "scope 检查不可用时保守阻断",
        tests: ["tests/engine/scope_controller.test.ts"],
        lifecycle_tests: ["tests/engine/scope_controller.test.ts"],
    },
    // ── 运行时安全 ──
    {
        id: "mc-runtime-safety",
        name: "运行时安全",
        owner_module: "src/engine/audit/runtime_safety.ts",
        owner_exports: ["buildEvidenceChain", "verifyEvidenceChain", "classifyCommand", "checkMigrationContract", "checkSupplyChain"],
        mechanism_type: "safety",
        status: "enforced",
        trigger: "命令执行和证据收集时",
        required_inputs: ["command", "evidence"],
        preconditions: [],
        outputs: ["ClassifiedCommand", "EvidenceBlock", "MigrationCheckResult", "SupplyChainCheckResult"],
        downstream_consumers: ["sf_verify", "sf_deliver", "command_execution_contract"],
        failure_modes: ["证据哈希截断", "证据链未在生产中使用", "迁移回滚校验同义反复", "供应链只验证文件名"],
        degradation_behavior: "安全检查不可用时保守阻断",
        tests: ["tests/engine/runtime_safety.test.ts"],
        lifecycle_tests: ["tests/engine/verification_scenario_matrix.test.ts"],
    },
    // ── 诊断码契约 ──
    {
        id: "mc-diagnostic-code-contract",
        name: "诊断码契约",
        owner_module: "src/engine/audit/diagnostic_registry.ts",
        owner_exports: ["registerDiagnostic", "getDiagnosticByCode", "listAllDiagnostics", "validateDiagnosticCoverage"],
        mechanism_type: "governance",
        status: "enforced",
        trigger: "诊断码注册与验证时",
        required_inputs: ["diagnostic_code", "area", "severity"],
        preconditions: [],
        outputs: ["DiagnosticCodeEntry", "DiagnosticCoverageReport"],
        downstream_consumers: ["validate-release", "enforcement_guard", "所有契约模块"],
        failure_modes: ["诊断码重复", "诊断码覆盖不完整"],
        degradation_behavior: "注册失败时返回错误信息",
        tests: ["tests/engine/verification_scenario_matrix.test.ts"],
        lifecycle_tests: ["tests/engine/verification_scenario_matrix.test.ts"],
    },
    // ── 契约状态存储 ──
    {
        id: "mc-contract-state-lifecycle",
        name: "契约状态存储",
        owner_module: "src/engine/contracts/contract_state_store.ts",
        owner_exports: ["ContractStateStore"],
        mechanism_type: "state_lifecycle",
        status: "enforced",
        trigger: "契约状态读写时",
        required_inputs: ["contract_id", "state_data"],
        preconditions: [],
        outputs: ["ContractState"],
        downstream_consumers: ["所有契约模块", "validate-release"],
        state_transitions: [
            "draft → active",
            "active → deprecated",
            "active → suspended",
            "suspended → active",
        ],
        failure_modes: ["状态转换无效", "并发写入冲突"],
        degradation_behavior: "状态存储不可用时降级为内存模式",
        tests: ["tests/engine/contract_registry.test.ts"],
        lifecycle_tests: ["tests/engine/contract_registry.test.ts"],
    },
    // ── 技术债务追踪 ──
    {
        id: "mc-tech-debt-lifecycle",
        name: "技术债务追踪",
        owner_module: "src/engine/audit/debt_tracker.ts",
        owner_exports: ["DebtTracker"],
        mechanism_type: "governance",
        status: "enforced",
        trigger: "validate-release 与技术债务评估时",
        required_inputs: ["debt_records", "thresholds"],
        preconditions: [],
        outputs: ["DebtReport", "DebtThresholdResult"],
        downstream_consumers: ["validate-release", "governance_report"],
        failure_modes: ["债务阈值溢出", "债务记录不一致"],
        degradation_behavior: "债务追踪不可用时降级为 advisory",
        tests: ["tests/engine/debt_tracker.test.ts"],
        lifecycle_tests: ["tests/engine/debt_tracker.test.ts"],
    },
    // ── 变更协调 ──
    {
        id: "mc-change-coordination",
        name: "变更协调",
        owner_module: "src/engine/change_coordinator.ts",
        owner_exports: ["checkConflicts"],
        mechanism_type: "analysis",
        status: "enforced",
        trigger: "多任务并发变更时",
        required_inputs: ["changed_files", "task_contexts"],
        preconditions: [],
        outputs: ["CoordinationCheckResult"],
        downstream_consumers: ["sf_expand", "sf_verify"],
        failure_modes: ["变更冲突未检测", "协调结果不一致"],
        degradation_behavior: "协调检查不可用时允许但标记为 advisory",
        tests: ["tests/engine/change_coordinator.test.ts"],
        lifecycle_tests: ["tests/engine/change_coordinator.test.ts"],
    },
    // ── 测试质量保证 ──
    {
        id: "mc-test-quality-assurance",
        name: "测试质量保证",
        owner_module: "src/engine/audit/test_quality.ts",
        owner_exports: ["analyzeTestQuality", "parseLcov"],
        mechanism_type: "verification",
        status: "enforced",
        trigger: "验证阶段测试质量评估",
        required_inputs: ["test_files", "coverage_data"],
        preconditions: [],
        outputs: ["TestQualityReport", "CoverageMap"],
        downstream_consumers: ["sf_verify", "validate-release"],
        failure_modes: ["测试覆盖不足", "测试质量不达标"],
        degradation_behavior: "质量数据不可用时降级为 advisory",
        tests: ["tests/engine/test_quality.test.ts"],
        lifecycle_tests: ["tests/engine/test_quality.test.ts"],
    },
    // ── 配置自动修复 ──
    {
        id: "mc-config-auto-repair",
        name: "配置自动修复",
        owner_module: "src/engine/config/config_auto_repair.ts",
        owner_exports: ["analyzeConfigRepair", "repairProjectConfig"],
        mechanism_type: "initialization",
        status: "advisory",
        trigger: "初始化配置修复时",
        required_inputs: ["project_path"],
        preconditions: ["项目目录可读"],
        outputs: ["ConfigRepairAnalysis", "ConfigRepairResult"],
        downstream_consumers: ["soloforge init", "validate-release"],
        failure_modes: ["修复建议不完整", "修复引入破坏性变更"],
        degradation_behavior: "自动修复失败时回退为手动配置",
        tests: ["tests/engine/config_auto_repair.test.ts"],
        lifecycle_tests: [],
    },
    // ── 24. existing_system_analysis (problem-50) ──
    {
        id: "mc-existing-system-analysis",
        name: "现有系统分析与差距分析",
        owner_module: "src/engine/contracts/existing_system_analysis.ts",
        owner_exports: ["detectProjectContext", "checkAnalysisGate", "createExistingSystemAnalysis"],
        mechanism_type: "analysis",
        status: "enforced",
        trigger: "existing_system 项目启动时",
        required_inputs: ["has_existing_system", "has_new_requirement"],
        preconditions: [],
        outputs: ["ProjectContext", "AnalysisGateResult"],
        downstream_consumers: ["sf_expand"],
        failure_modes: ["existing_system 未分析"],
        degradation_behavior: "未分析时阻断后续流程",
        tests: ["tests/engine/extension_scenario_matrix.test.ts"],
        lifecycle_tests: ["tests/engine/extension_scenario_matrix.test.ts"],
    },
    // ── 25. coding_readiness (problem-51) ──
    {
        id: "mc-coding-readiness",
        name: "编码准备门与测试优先",
        owner_module: "src/engine/contracts/coding_readiness_gate.ts",
        owner_exports: ["evaluateCodingReadiness", "createTestFirstPlan", "performMainlineConsumptionCheck"],
        mechanism_type: "governance",
        status: "enforced",
        trigger: "编码开始前",
        required_inputs: ["coding_readiness_contract", "preconditions"],
        preconditions: [],
        outputs: ["ReadinessEvaluationResult", "TestFirstPlan"],
        downstream_consumers: ["sf_expand"],
        failure_modes: ["编码作为第一步", "blocked 状态允许编码"],
        degradation_behavior: "准备不足时阻断编码",
        tests: ["tests/engine/extension_scenario_matrix.test.ts"],
        lifecycle_tests: ["tests/engine/extension_scenario_matrix.test.ts"],
    },
    // ── 26. local_acceptance (problem-52) ──
    {
        id: "mc-local-acceptance",
        name: "本地 Docker/浏览器验收",
        owner_module: "src/engine/contracts/local_docker_acceptance.ts",
        owner_exports: ["validateFinalAccess", "requiresLocalAcceptance", "performBrowserAcceptance"],
        mechanism_type: "verification",
        status: "enforced",
        trigger: "本地验收阶段",
        required_inputs: ["final_access", "project_run_mode"],
        preconditions: [],
        outputs: ["LocalDockerAcceptanceContract", "FinalAccessValidationResult"],
        downstream_consumers: ["sf_verify", "delivery"],
        failure_modes: ["无本地 URL", "浏览器验收失败未修复"],
        degradation_behavior: "验收不通过时阻断交付",
        tests: ["tests/engine/extension_scenario_matrix.test.ts"],
        lifecycle_tests: ["tests/engine/extension_scenario_matrix.test.ts"],
    },
    // ── 27. workflow_template_pack (problem-53) ──
    {
        id: "mc-workflow-template-pack",
        name: "工作流模板包消费",
        owner_module: "src/engine/contracts/workflow_template_pack.ts",
        owner_exports: ["validateWorkflowTemplatePack", "advanceTemplateConsumptionStatus", "createTemplateConsumptionEvidence"],
        mechanism_type: "artifact_management",
        status: "enforced",
        trigger: "模板消费验证时",
        required_inputs: ["pack_contract", "consumption_evidences"],
        preconditions: [],
        outputs: ["WorkflowTemplatePackContract", "PackValidationResult"],
        downstream_consumers: ["sf_expand", "sf_verify"],
        failure_modes: ["模板停在中间状态", "消费 pipeline 不完整"],
        degradation_behavior: "消费不完整时阻断",
        tests: ["tests/engine/extension_scenario_matrix.test.ts"],
        lifecycle_tests: ["tests/engine/extension_scenario_matrix.test.ts"],
    },
    // ── 28. evolution_regression (problem-54) ──
    {
        id: "mc-evolution-regression",
        name: "演进回归与新问题门控",
        owner_module: "src/engine/contracts/evolution_regression_gate.ts",
        owner_exports: ["performEvolutionGate", "checkDuplicateIssue", "createNewIssueRegressionGate"],
        mechanism_type: "governance",
        status: "enforced",
        trigger: "新问题登记时",
        required_inputs: ["issue_candidate"],
        preconditions: [],
        outputs: ["NewIssueRegressionGate", "EvolutionGateResult"],
        downstream_consumers: ["sf_expand"],
        failure_modes: ["重复问题未检测", "无门控被接受"],
        degradation_behavior: "门控未通过时拒绝问题",
        tests: ["tests/engine/extension_scenario_matrix.test.ts"],
        lifecycle_tests: ["tests/engine/extension_scenario_matrix.test.ts"],
    },
];
//# sourceMappingURL=contracts-audit.js.map