# 科研五阶段产物 Gate 流水线（模板）— 对应 docs/PRODUCT_GATE_DESIGN.md §8.1。
# plan → literature → simulation → analysis → paper，逐级验收。
# 注：plan/literature 已可端到端跑（见 research-demo.yml）；simulation/analysis/paper
# 需要带工具的 react agent（WriteFile / 代码执行），属 v1.1 工作，这里作为模板占位。
pipeline:
  id: research-v1
  name: 科研五阶段流水线
  defaults:
    on_fail: retry
    retry: 2

  stages:
    - id: plan
      name: 研究计划
      agent: {ref: agents/planner.yml}
      produces:
        - {name: plan.md, type: md, path: "final/plan.md", required: true}
      gate:
        kind: rule
        rule: 'has("plan.md") and regex("plan.md", "(?i)hypothesis")'

    - id: literature
      name: 文献综述
      consumes: [plan]
      agent: {ref: agents/lit-mapper.yml}
      produces:
        - {name: refs.json, type: json, path: "results/refs.json", required: true}
        - {name: survey.md, type: md,   path: "final/survey.md",   required: true}
      gate:
        kind: rule
        rule: 'has("refs.json") and json_len("refs.json") >= 10'

    - id: simulation
      name: 仿真实验
      consumes: [plan, literature]
      agent: {ref: agents/simulator.yml}    # react + 代码执行工具（v1.1）
      produces:
        - {name: sim_results, type: dir, path: "results/sim/*", required: true}
      gate:
        kind: rule
        rule: 'count() >= 1'
      on_fail: halt

    - id: analysis
      name: 结果分析
      consumes: [simulation]
      agent: {ref: agents/analyst.yml}
      produces:
        - {name: analysis.md, type: md, path: "final/analysis.md", required: true}
      gate:
        kind: llm_judge
        judge:
          model: {provider: ollama, name: qwen2.5:7b}
          rubric: "分析是否覆盖所有仿真指标、有统计显著性讨论、结论有数据支撑"
          threshold: 0.7

    - id: paper
      name: 论文成稿
      consumes: [plan, literature, analysis]
      agent: {ref: agents/writer.yml}
      produces:
        - {name: paper.md, type: md, path: "final/paper.md", required: true}
      gate:
        kind: llm_judge
        judge:
          rubric: "结构完整(摘要/方法/结果/讨论)、引用与 refs.json 一致、无明显逻辑断裂"
          threshold: 0.8
