/**
 * IssueDetailAcceptance 生产注册表。
 *
 * 提供 listKnowledgeIssueDetailAcceptances() 和 validateKnowledgeIssueDetailAcceptance()。
 * 每条验收记录的 mainline_consumption_check 必须可追溯到真实源码调用链。
 */
import { getContractById } from "../contracts/contract_registry.js";
/** 全部 9 个问题的验收注册表 */
export const KNOWLEDGE_ISSUE_ACCEPTANCES = [
    {
        issue_id: "problem-7",
        contract_id: "knowledge_lifecycle_contract",
        must_keep_details: [
            "knowledge_lifecycle_status 使用 draft/active/pending_review/quarantine/deprecated",
            "sovereignty 使用 normal/core",
            "staged 为 write phase 不是 lifecycle state",
        ],
        required_entrypoints: ["evaluatePromotion"],
        required_contract_fields: ["knowledge_lifecycle_status", "sovereignty", "knowledge_write_stage"],
        required_mechanism_hooks: ["AI inference 晋级阻断", "core 主权变更人工确认", "无证据晋级阻断"],
        required_template_or_adapter_updates: [], // not_applicable: 知识生命周期是机制层治理，不直接产生模板或 adapter 更新
        required_sync_or_migration_paths: ["旧 status 字段迁移到 knowledge_lifecycle_status"],
        required_evidence_refs: ["AI inference 阻断证据", "人工确认晋级证据"],
        required_diagnostics: [],
        regression_cases: ["AI inference 晋级 active", "draft 自动晋级 active"],
        cross_scenario_coverage: ["A-1", "A-2", "A-3", "A-4"],
        user_project_impact: ["知识生命周期状态更精确", "staged 改为 write phase"],
        soloforge_self_impact: ["内部知识使用新状态模型"],
        owner_files: ["src/engine/knowledge/knowledge_lifecycle.ts"],
        mainline_consumption_check: ["knowledge_evolution.validateCandidateTrust → knowledge_lifecycle.evaluatePromotion → AI inference 晋级阻断"],
        not_done_if_missing: ["evaluatePromotion AI inference 阻断"],
    },
    {
        issue_id: "problem-10",
        contract_id: "chinese_semantic_priority_contract",
        must_keep_details: ["zh_first 域中文优先", "code_native 域不翻译"],
        required_entrypoints: ["evaluateSemanticPriority"],
        required_contract_fields: [],
        required_mechanism_hooks: ["中文项目英文模板污染检测"],
        required_template_or_adapter_updates: [], // not_applicable: 中文语义优先是机制层治理，不直接产生模板或 adapter 更新
        required_sync_or_migration_paths: [],
        required_evidence_refs: ["中文语义合规证据"],
        required_diagnostics: [],
        regression_cases: ["中文项目被英文模板污染"],
        cross_scenario_coverage: ["H-1", "H-2", "H-3"],
        user_project_impact: ["中文项目语义保护"],
        soloforge_self_impact: ["内部注释中文"],
        owner_files: ["src/engine/knowledge/chinese_semantic_priority.ts"],
        mainline_consumption_check: ["CLI validate-knowledge → knowledge_scenario_registry → evaluateSemanticPriority → 中文语义校验"],
        not_done_if_missing: ["中文项目被英文模板保护"],
    },
    {
        issue_id: "problem-14",
        contract_id: "knowledge_evolution_contract",
        must_keep_details: ["证据晋级", "来源信任分级", "AI 推理写入限制"],
        required_entrypoints: ["evaluateCandidateTrust", "validateAiInferenceWrite"],
        required_contract_fields: [],
        required_mechanism_hooks: ["AI 推理只能 draft/quarantine"],
        required_template_or_adapter_updates: [], // not_applicable: 知识演进是机制层治理，不直接产生模板或 adapter 更新
        required_sync_or_migration_paths: [],
        required_evidence_refs: ["证据验证通过"],
        required_diagnostics: [],
        regression_cases: ["AI inference 写入 core", "AI inference 写入 active"],
        cross_scenario_coverage: ["A-6", "A-7", "A-8", "A-9"],
        user_project_impact: ["知识演进更安全"],
        soloforge_self_impact: ["AI 产出知识受限"],
        owner_files: ["src/engine/knowledge/knowledge_evolution.ts"],
        mainline_consumption_check: ["CLI validate-knowledge → knowledge_scenario_registry → evaluateCandidateTrust + validateAiInferenceWrite → AI 推理限制"],
        not_done_if_missing: ["AI inference 写入限制"],
    },
    {
        issue_id: "problem-21",
        contract_id: "documentation_governance_contract",
        must_keep_details: ["设计文档准入", "禁止内容检查", "注册表冲突检测"],
        required_entrypoints: ["validateDesignDocEligibility"],
        required_contract_fields: [],
        required_mechanism_hooks: ["proposed 不得写入设计文档", "设计文档不得含施工流水"],
        required_template_or_adapter_updates: [], // not_applicable: 文档治理是机制层治理，不直接产生模板或 adapter 更新
        required_sync_or_migration_paths: [],
        required_evidence_refs: ["准入验证证据"],
        required_diagnostics: [],
        regression_cases: ["proposed 写入设计文档", "设计文档含施工日志"],
        cross_scenario_coverage: ["H-8", "H-9", "H-10", "H-11"],
        user_project_impact: ["文档治理更严格"],
        soloforge_self_impact: ["自身设计文档治理"],
        owner_files: ["src/engine/knowledge/documentation_governance.ts"],
        mainline_consumption_check: ["CLI validate-knowledge → knowledge_scenario_registry → validateDesignDocEligibility → 设计文档准入"],
        not_done_if_missing: ["proposed 准入阻断"],
    },
    {
        issue_id: "problem-25",
        contract_id: "template_sync_contract",
        must_keep_details: ["用户修改模板不得覆盖", "core knowledge 不得自动同步", "dry-run 先行"],
        required_entrypoints: ["executeSync", "validateSyncSafety"],
        required_contract_fields: [],
        required_mechanism_hooks: ["用户修改保护", "core knowledge 保护"],
        required_template_or_adapter_updates: [], // not_applicable: 模板同步契约自身即为模板层治理机制
        required_sync_or_migration_paths: ["模板 schema 迁移"],
        required_evidence_refs: ["用户修改保护证据"],
        required_diagnostics: [],
        regression_cases: ["用户修改模板被覆盖", "core knowledge 被同步"],
        cross_scenario_coverage: ["B-1", "B-2", "B-3", "B-4"],
        user_project_impact: ["模板同步安全"],
        soloforge_self_impact: ["自身模板同步"],
        owner_files: ["src/engine/templates/template_sync.ts"],
        mainline_consumption_check: ["CLI sync-templates → cmdSyncTemplates → executeSync → validateSyncSafety → 用户修改保护+core 不写"],
        not_done_if_missing: ["用户修改保护"],
    },
    {
        issue_id: "problem-30",
        contract_id: "user_promise_contract",
        must_keep_details: ["README 命令漂移检测", "CLI 默认行为安全"],
        required_entrypoints: ["validateUserPromise"],
        required_contract_fields: [],
        required_mechanism_hooks: ["README 命令必须映射真实 CLI contract", "sync-templates 默认 dry_run"],
        required_template_or_adapter_updates: [], // not_applicable: 用户承诺是机制层治理，不直接产生模板或 adapter 更新
        required_sync_or_migration_paths: [],
        required_evidence_refs: ["README 漂移检测证据"],
        required_diagnostics: [],
        regression_cases: ["README fake 命令", "sync-templates 非 dry_run"],
        cross_scenario_coverage: ["D-1", "D-2", "D-4", "D-5"],
        user_project_impact: ["CLI 行为可预期"],
        soloforge_self_impact: ["自身 README 一致性"],
        owner_files: ["src/engine/contracts/user_promise.ts"],
        mainline_consumption_check: ["CLI validate → cmdValidate → validateUserPromise → detectReadmeDrift → README 命令一致性检查"],
        not_done_if_missing: ["README 漂移检测"],
    },
    {
        issue_id: "problem-31",
        contract_id: "adapter_prompt_contract_entry",
        must_keep_details: ["必须章节检查", "禁止声明检测", "next_allowed_tools 约束"],
        required_entrypoints: ["validateAdapterPrompt"],
        required_contract_fields: [],
        required_mechanism_hooks: ["forbidden claim 检测", "必须章节检查"],
        required_template_or_adapter_updates: ["adapter prompt 模板"],
        required_sync_or_migration_paths: [],
        required_evidence_refs: ["适配器合规验证证据"],
        required_diagnostics: [],
        regression_cases: ["forbidden claim 通过", "缺少必须章节"],
        cross_scenario_coverage: ["C-1", "C-2", "C-3", "C-4"],
        user_project_impact: ["适配器行为可控"],
        soloforge_self_impact: ["自身适配器合规"],
        owner_files: ["src/engine/adapter_prompt_contract.ts"],
        mainline_consumption_check: ["CLI sync-adapters → cmdSyncAdapters → validateAdapterPrompt → forbidden claim 检测+必须章节校验"],
        not_done_if_missing: ["forbidden claim 检测"],
    },
    {
        issue_id: "problem-35",
        contract_id: "release_compatibility_contract",
        must_keep_details: ["migrate 默认 dry-run", "apply 必须用户确认", "回滚支持"],
        required_entrypoints: ["createMigrationPlan", "validateMigrationSafety"],
        required_contract_fields: [],
        required_mechanism_hooks: ["apply 无确认阻断", "回滚路径必须"],
        required_template_or_adapter_updates: [], // not_applicable: 发布兼容是机制层治理，不直接产生模板或 adapter 更新
        required_sync_or_migration_paths: ["schema 迁移路径"],
        required_evidence_refs: ["迁移安全验证证据"],
        required_diagnostics: [],
        regression_cases: ["migrate apply 无确认", "无回滚路径"],
        cross_scenario_coverage: ["E-4", "E-5", "E-6"],
        user_project_impact: ["升级迁移安全"],
        soloforge_self_impact: ["自身版本兼容"],
        owner_files: ["src/engine/knowledge/release_compatibility.ts"],
        mainline_consumption_check: ["CLI migrate → cmdMigrate → createMigrationPlan → validateMigrationSafety → apply 无确认阻断"],
        not_done_if_missing: ["migrate apply 确认"],
    },
    {
        issue_id: "problem-41",
        contract_id: "language_policy_override_contract",
        must_keep_details: ["支持 zh_first/en_first/bilingual/source_preserving", "语义污染检测"],
        required_entrypoints: ["getLanguagePolicyConfig", "detectSemanticPollution"],
        required_contract_fields: [],
        required_mechanism_hooks: ["中文项目英文污染检测", "英文项目可配置"],
        required_template_or_adapter_updates: [], // not_applicable: 语言策略覆盖是机制层治理，不直接产生模板或 adapter 更新
        required_sync_or_migration_paths: [],
        required_evidence_refs: ["语言策略配置证据"],
        required_diagnostics: [],
        regression_cases: ["中文项目被英文模板污染", "英文项目被强制中文"],
        cross_scenario_coverage: ["F-1", "F-5", "F-7"],
        user_project_impact: ["多语言项目支持"],
        soloforge_self_impact: ["自身语言策略"],
        owner_files: ["src/engine/knowledge/language_policy.ts"],
        mainline_consumption_check: ["CLI validate-knowledge → knowledge_scenario_registry → getLanguagePolicyConfig + detectSemanticPollution → 语义污染检测"],
        not_done_if_missing: ["语义污染检测"],
    },
];
/**
 * 列出全部 IssueDetailAcceptance。
 */
export function listKnowledgeIssueDetailAcceptances() {
    return KNOWLEDGE_ISSUE_ACCEPTANCES;
}
/**
 * 验证单个 IssueDetailAcceptance 的完整性。
 *
 * 规则：
 *   - issue_id 必须对应 roadmap 中存在的问题
 *   - contract_id 必须在契约注册表中存在
 *   - must_keep_details 不得为空
 *   - required_entrypoints 不得为空
 *   - owner_files 不得为空
 *   - not_done_if_missing 不得为空
 *   - regression_cases 不得为空
 */
export function validateKnowledgeIssueDetailAcceptance(acceptance) {
    const findings = [];
    if (!acceptance.issue_id) {
        findings.push({ issue_id: "", rule: "issue_id_required", severity: "hard_fail", message_zh: "issue_id 不得为空" });
        return findings;
    }
    const contract = getContractById(acceptance.contract_id);
    if (!contract) {
        findings.push({
            issue_id: acceptance.issue_id,
            rule: "contract_id_exists",
            severity: "hard_fail",
            message_zh: `contract_id "${acceptance.contract_id}" 在契约注册表中不存在`,
        });
    }
    if (!acceptance.must_keep_details || acceptance.must_keep_details.length === 0) {
        findings.push({
            issue_id: acceptance.issue_id,
            rule: "must_keep_details_non_empty",
            severity: "hard_fail",
            message_zh: `${acceptance.issue_id} must_keep_details 不得为空`,
        });
    }
    if (!acceptance.required_entrypoints || acceptance.required_entrypoints.length === 0) {
        findings.push({
            issue_id: acceptance.issue_id,
            rule: "required_entrypoints_non_empty",
            severity: "hard_fail",
            message_zh: `${acceptance.issue_id} required_entrypoints 不得为空`,
        });
    }
    if (!acceptance.owner_files || acceptance.owner_files.length === 0) {
        findings.push({
            issue_id: acceptance.issue_id,
            rule: "owner_files_non_empty",
            severity: "hard_fail",
            message_zh: `${acceptance.issue_id} owner_files 不得为空`,
        });
    }
    if (!acceptance.not_done_if_missing || acceptance.not_done_if_missing.length === 0) {
        findings.push({
            issue_id: acceptance.issue_id,
            rule: "not_done_if_missing_non_empty",
            severity: "hard_fail",
            message_zh: `${acceptance.issue_id} not_done_if_missing 不得为空`,
        });
    }
    if (!acceptance.regression_cases || acceptance.regression_cases.length === 0) {
        findings.push({
            issue_id: acceptance.issue_id,
            rule: "regression_cases_non_empty",
            severity: "hard_fail",
            message_zh: `${acceptance.issue_id} regression_cases 不得为空`,
        });
    }
    return findings;
}
//# sourceMappingURL=knowledge_acceptance_registry.js.map