/**
 * Mechanism Contract Registry — 核心管线机制契约（1-8）。
 *
 * 包括 intent_router、classifier、intent_expander、knowledge_matching、
 * knowledge_injection_boundary、task_context_lifecycle、verifier、workspace_resumer。
 */
/** 核心管线 P0 机制契约 */
export const PIPELINE_CONTRACTS = [
    // ── 1. intent_router ──
    {
        id: "mc-intent-router",
        name: "Intent Router",
        owner_module: "src/engine/pipeline/intent_router.ts",
        owner_exports: ["routeIntent"],
        mechanism_type: "routing",
        status: "enforced",
        trigger: "sf_classify 调用后、classifier 分类前",
        required_inputs: ["intent"],
        preconditions: ["intent 非空字符串"],
        outputs: ["route_decision", "route", "execution_shape", "mutation_allowed", "input_materials", "output_artifact", "pipeline_hint", "missing_required_inputs"],
        downstream_consumers: ["classifier", "intent_expander", "task_planner"],
        failure_modes: [
            "artifact_generation 被 skip（应路由到 code_change 或 artifact_generation）",
            "source_extraction 允许 mutation（应为 read-only）",
            "direct_answer 与产物语义混淆（应区分回答与生成）",
        ],
        degradation_behavior: "路由失败时默认降级为 code_change，写入 route_decision.degraded=true",
        tests: ["tests/engine/intent_router.test.ts"],
        lifecycle_tests: ["tests/adapters/tools_lifecycle.test.ts"],
    },
    // ── 2. classifier (deprecated → mc-intent-router) ──
    {
        id: "mc-classifier",
        name: "Classifier (deprecated → mc-intent-router)",
        owner_module: "src/engine/pipeline/classifier.ts",
        owner_exports: ["classify"],
        mechanism_type: "classification",
        status: "deprecated",
        trigger: "sf_classify 调用时，routeIntent 之后",
        required_inputs: ["intent", "route_decision"],
        preconditions: ["route_decision 已由 intent_router 生成"],
        outputs: ["task_type", "risk", "complexity", "ambiguity", "affected_repos", "mode", "strategy", "route_decision"],
        downstream_consumers: ["intent_router (compatibility display)", "task_context", "compatibility display"],
        failure_modes: [
            "task_type 覆盖 route_decision 的裁决结果",
            "strategy 字段被当作入口裁决而非兼容展示",
        ],
        degradation_behavior: "classifier 仅提供兼容字段和辅助分类，不能重新夺回入口裁决权；route_decision 始终由 intent_router 决定",
        tests: ["tests/engine/classifier.test.ts"],
        lifecycle_tests: ["tests/adapters/tools_lifecycle.test.ts"],
        notes: "已废弃: classifier 是 intent_router 的一部分，正式机制 ID 为 mc-intent-router。owner_mechanism_id 必须指向 mc-intent-router。不可删除代码：classifier 仍被 sf_classify handler 和 intent_expander 作为兼容层调用，删除会破坏向后兼容的 task_type/risk/complexity 字段。",
    },
    // ── 3. intent_expander ──
    {
        id: "mc-intent-expander",
        name: "Intent Expander",
        owner_module: "src/engine/pipeline/intent_expander.ts",
        owner_exports: ["expand"],
        mechanism_type: "expansion",
        status: "enforced",
        trigger: "sf_expand 调用时",
        required_inputs: ["classification", "route_decision", "matched_knowledge"],
        preconditions: ["任务处于 classifying 或 clarifying 状态", "route_decision 已生成"],
        outputs: ["expansion", "prompt", "scope", "acceptance_criteria"],
        downstream_consumers: ["sf_expand handler", "executor", "verifier"],
        failure_modes: [
            "source_extraction 路由的 prompt 包含代码修改指令而非产物提取指令",
            "read_only_analysis 生成的 prompt 包含修改源码的指令",
            "circuit breaker 置信度不足时仍生成执行指令而非澄清请求",
        ],
        degradation_behavior: "confidence < 阈值时返回 clarification prompt 而非执行指令，consumption_mode=required 的模板缺失时报错",
        tests: ["tests/engine/intent_expander_integration.test.ts"],
        lifecycle_tests: ["tests/adapters/tools_lifecycle.test.ts"],
    },
    // ── 4. knowledge_matching (deprecated → mc-knowledge-injection-boundary) ──
    {
        id: "mc-knowledge-matching",
        name: "Knowledge Matching (deprecated → mc-knowledge-injection-boundary)",
        owner_module: "src/knowledge/index_manager.ts",
        owner_exports: ["KnowledgeIndexManager"],
        mechanism_type: "knowledge_matching",
        status: "deprecated",
        trigger: "expand() 内部调用 knowledgeIndex.query()",
        required_inputs: ["route_decision", "output_artifact.kind", "pipeline_hint", "knowledge_index"],
        preconditions: ["knowledge index 已 build"],
        outputs: ["matched_patterns", "injected_templates"],
        downstream_consumers: ["intent_expander prompt builder"],
        failure_modes: [
            "prototype_spec output_artifact 未命中原型说明模版",
            "required knowledge 缺失时退回 code prompt 而非报错",
            "draft/quarantine 状态知识默认注入 prompt",
            "三道门过滤后无注入结果但无注入报告",
        ],
        degradation_behavior: "整体 advisory，但 required branch（prototype_spec → 原型说明模版）为 enforced：缺失时必须报错而非静默降级。其他分支缺失时优雅降级为空匹配",
        tests: ["tests/engine/intent_expander_integration.test.ts"],
        lifecycle_tests: ["tests/adapters/tools_lifecycle.test.ts"],
        notes: "已废弃: knowledge_matching 是 knowledge_injection_boundary 的一部分，正式机制 ID 为 mc-knowledge-injection-boundary。不可删除代码：index_manager.query() 仍被 intent_expander 直接调用作为知识检索入口，且 parseEntry() 是知识索引构建的必经路径，删除会破坏整个知识管道。",
    },
    // ── 5. knowledge_injection_boundary ──
    {
        id: "mc-knowledge-injection-boundary",
        name: "Knowledge Injection Boundary",
        owner_module: "src/engine/knowledge/knowledge_injection_boundary.ts",
        owner_exports: ["enforceKnowledgeInjectionBoundary", "validateInjectionReport"],
        mechanism_type: "safety",
        status: "enforced",
        trigger: "expand() 内 queryKnowledgeForRoute 后的三道门过滤",
        required_inputs: ["knowledge_entries", "route_decision", "consumable_assets", "budget"],
        preconditions: ["knowledge index 已 build", "route_decision 已生成"],
        outputs: ["KnowledgeInjectionReport (indexed, injectable, injected_required, injected_supporting, advisory_only, excluded, missing_required_knowledge, governance_findings, conflicts, budget)"],
        downstream_consumers: ["prompt builder", "intent_expander ExpandResult"],
        failure_modes: [
            "draft/quarantine/deprecated 状态知识绕过边界进入 prompt",
            "错误 route 注入错误模板（如 code_change 注入了 source_extraction 模板）",
            "consumption_mode=required 资产缺失时静默降级而非报错",
            "pending_review 知识出现在 injected 而非 advisory_only",
            "core 知识被 normal 知识静默覆盖无 conflict 记录",
            "budget 不足时 required 被 supporting 挤掉",
            "无 KnowledgeInjectionReport 生成",
        ],
        degradation_behavior: "draft/quarantine/deprecated 知识被过滤，不进入 prompt。pending_review 进入 advisory_only 带 warning。route 不匹配时跳过模板注入。budget 不足时优先保留 required",
        tests: [
            "tests/engine/knowledge_injection_boundary.test.ts",
            "tests/engine/intent_expander_integration.test.ts",
            "tests/engine/knowledge_isolation.test.ts",
            "tests/engine/knowledge_sovereignty.test.ts",
        ],
        lifecycle_tests: ["tests/adapters/tools_lifecycle.test.ts"],
    },
    // ── 6. task_context_lifecycle ──
    {
        id: "mc-task-context-lifecycle",
        name: "Task Context Lifecycle",
        owner_module: "src/engine/pipeline/task_context.ts",
        owner_exports: ["TaskContextManager"],
        mechanism_type: "state_lifecycle",
        status: "enforced",
        trigger: "sf_classify/sf_expand/sf_verify/sf_learn 调用时",
        required_inputs: ["intent", "product_profile", "classification_before_expand", "expansion_before_executing", "execution_before_verifying"],
        preconditions: ["stateDir 已初始化"],
        outputs: ["task_state", "task_id", "current_status"],
        downstream_consumers: ["sf_expand", "sf_verify", "sf_learn", "sf_status", "workspace_resumer"],
        state_transitions: [
            "init → classifying",
            "classifying → expanding",
            "classifying → clarifying",
            "clarifying → expanding",
            "expanding → executing",
            "executing → verifying",
            "verifying → learning",
            "learning → done",
            "learning → retrying",
            "retrying → expanding",
        ],
        cleanup_hooks: [
            "clear_diff_ownership",
            "release_scope_lease",
            "clear_current_active_task_pointer",
        ],
        failure_modes: [
            "classifying 状态直接调用 sf_verify（应先 expand）",
            "executing 状态再次 sf_expand（不可重入）",
            "done 状态调用 sf_expand（任务已结束）",
        ],
        degradation_behavior: "非法状态转换返回 isError，不静默忽略",
        tests: ["tests/engine/task_context.test.ts"],
        lifecycle_tests: ["tests/adapters/tools_lifecycle.test.ts"],
    },
    // ── 7. verifier ──
    {
        id: "mc-verifier",
        name: "Verifier",
        owner_module: "src/engine/release/verifier.ts",
        owner_exports: ["generateVerifyCommands"],
        mechanism_type: "verification",
        status: "enforced",
        trigger: "sf_verify 调用时",
        required_inputs: ["expansion", "execution_shape", "changed_files_or_output_artifact"],
        preconditions: ["任务处于 executing 状态", "已有 expansion 结果"],
        outputs: ["verify_commands", "verification_result", "evidence"],
        downstream_consumers: ["sf_verify handler", "task_context", "sf_learn"],
        failure_modes: [
            "single_artifact/source_extraction 默认要求 build+test（应为轻量验证）",
            "verification 结果未保存到 task context 就标记 done/learning",
        ],
        degradation_behavior: "execution_shape 决定验证策略：code_execution 用完整 build+test，single_artifact/source_extraction 用轻量检查",
        tests: ["tests/engine/verifier_phase25.test.ts"],
        lifecycle_tests: ["tests/adapters/tools_lifecycle.test.ts"],
    },
    // ── 8. workspace_resumer (deprecated → mc-task-context-lifecycle) ──
    {
        id: "mc-workspace-resumer",
        name: "Workspace Resumer (deprecated → mc-task-context-lifecycle)",
        owner_module: "src/engine/pipeline/workspace_resumer.ts",
        owner_exports: ["scanAndResume", "cleanupStaleTasks"],
        mechanism_type: "state_lifecycle",
        status: "deprecated",
        trigger: "sf_status action=resume 或会话启动时",
        required_inputs: ["task_state_directory", "current_task_pointer", "active_task_list"],
        preconditions: ["stateDir 存在"],
        outputs: ["resume_report", "active_task_candidates", "cleanup_report"],
        downstream_consumers: ["sf_status", "sf_resume_workspace", "TaskContextManager"],
        state_transitions: [
            "found_executing → resume_to_executing",
            "found_verifying → resume_to_verifying",
            "found_retrying → resume_to_retrying",
        ],
        cleanup_hooks: [
            "cleanupOrphanLeases",
            "cleanupStaleTasks",
            "current_pointer_repair",
        ],
        failure_modes: [
            "中断后 current pointer 指向已完成的任务",
            "orphan scope lease 未清理导致 scope 被永久占用",
        ],
        degradation_behavior: "corrupt task 标记为 unrecoverable，不阻塞其他任务恢复",
        tests: ["tests/engine/workspace_resumer.test.ts"],
        lifecycle_tests: ["tests/engine/workspace_resumer.test.ts", "tests/adapters/tools_lifecycle.test.ts"],
        notes: "已废弃: workspace_resumer 是 task_context_lifecycle 的一部分，正式机制 ID 为 mc-task-context-lifecycle。不可删除代码：scanAndResume() 仍被 sf_status handler 作为会话恢复入口调用，cleanupStaleTasks() 是状态清理的唯一路径，删除会导致中断任务无法恢复。",
    },
];
//# sourceMappingURL=contracts-pipeline.js.map