diff --git a/services/code_review_pipeline_service.py b/services/code_review_pipeline_service.py index 234f3f0..d5fb9f0 100644 --- a/services/code_review_pipeline_service.py +++ b/services/code_review_pipeline_service.py @@ -328,15 +328,14 @@ class CodeReviewPipeline: "priority": "critical|high|medium|low", "auto_fix": true|false, "reasoning": "決策理由(繁體中文,一句話,需含具體數字)", - "fix_files": ["需自動修復的檔案(最多3個,只填 CRITICAL/HIGH 問題的檔案)"], - "human_review_needed": true|false + "fix_files": ["需自動修復的檔案(最多5個,所有有問題的檔案)"], + "human_review_needed": false }} -規則: -- CRITICAL ≥ 1 → priority=critical, auto_fix=true -- HIGH ≥ 3 → priority=high, auto_fix=true -- HIGH 1-2 → priority=high, auto_fix=false, human_review_needed=true -- 其餘 → priority=medium|low, auto_fix=false""" +規則(依 ADR-014,所有問題一律自動修復,安全網為 Git+Gitea CI/CD 回滾): +- 任何 finding ≥ 1 → auto_fix=true,human_review_needed=false +- priority 按最嚴重 severity 決定:CRITICAL>HIGH>MEDIUM>LOW +- fix_files 填入所有有問題的檔案(不限 CRITICAL/HIGH)""" resp = elephant_service.generate( prompt=prompt, @@ -349,24 +348,25 @@ class CodeReviewPipeline: except Exception as e: logger.warning("[CodeReview] ElephantAlpha 決策失敗,回退規則: %s", e) - # 規則 fallback - auto_fix = critical_n > 0 or high_n >= 3 + # 規則 fallback(ADR-014:任何 finding 一律自動修復,回滾防線由 Git+CI/CD 負責) + has_findings = len(findings) > 0 + auto_fix = has_findings priority = ( "critical" if critical_n > 0 else "high" if high_n > 0 else - "medium" if sev["medium"] > 0 else "low" + "medium" if sev["medium"] > 0 else + "low" if sev["low"] > 0 else "low" ) fix_files = list({ - f.get("file", "") for f in findings - if f.get("severity") in ("CRITICAL", "HIGH") and f.get("file") - })[:3] + f.get("file", "") for f in findings if f.get("file") + })[:5] return { "priority": priority, "auto_fix": auto_fix, - "reasoning": f"規則判斷:CRITICAL={critical_n} HIGH={high_n},{'觸發自動修復' if auto_fix else '需人工審查'}", + "reasoning": f"ADR-014 規則:CRITICAL={critical_n} HIGH={high_n} MEDIUM={sev['medium']} LOW={sev['low']},{'觸發自動修復' if auto_fix else '無問題無需修復'}", "fix_files": fix_files, - "human_review_needed": not auto_fix and (critical_n + high_n) > 0, + "human_review_needed": False, } # ── Step 5:NemoTron 派遣 ──────────────────────────────────────────────────