"""B6 / B7 / B8 wiring — DPO-cross-doc, doc-staleness, CMP-fingerprint. Three small, deterministic checks added after B5. Each writes one or more findings into `state["extra_findings"]` and a tiny HTML block into `state["extra_findings_html"]` that the V2 renderer concatenates between B5 (AI-Act) and the legacy section block. """ from __future__ import annotations import html import logging from compliance.services.cmp_fingerprint_check import check_cmp_fingerprint from compliance.services.cross_doc_dpo_check import check_dpo_cross_doc from compliance.services.doc_staleness_check import check_staleness logger = logging.getLogger(__name__) def run_b6b7b8(state: dict) -> None: findings: list[dict] = [] dpo = check_dpo_cross_doc(state) if dpo: findings.append(dpo) stale = check_staleness(state) findings.extend(stale) cmp = check_cmp_fingerprint(state) if cmp: findings.append(cmp) state["extra_findings"] = findings if findings: state["extra_findings_html"] = _render(findings) logger.info( "B6/B7/B8 extra: %d findings (DPO=%d, staleness=%d, CMP=%d)", len(findings), 1 if dpo else 0, len(stale), 1 if cmp else 0, ) def _render(findings: list[dict]) -> str: cards = [] for f in findings: sev = (f.get("severity") or "").upper() color = "#dc2626" if sev == "HIGH" else ( "#f59e0b" if sev == "MEDIUM" else "#64748b" ) evidence_html = "" if f.get("evidence_dse"): evidence_html = ( "
" f"In DSE: {html.escape(', '.join(f['evidence_dse']))}" "
" ) if f.get("doc_date"): evidence_html = ( "
" f"Stand: {html.escape(f['doc_date'])} " f"({f.get('age_years','?')} Jahre alt, Cap " f"{f.get('threshold_years','?')} Jahre)" "
" ) if f.get("detected_provider"): evidence_html = ( "
" f"Erkannter Provider: " f"{html.escape(f['detected_provider'])}" "
" ) cards.append( f"
" f"
" f"{sev} · {html.escape(f.get('check_id') or '')}
" f"
" f"{html.escape(f.get('title') or '')}
" f"
" f"{html.escape(f.get('norm') or '')}
" f"{evidence_html}" f"
" f"→ Empfehlung: " f"{html.escape(f.get('action') or '')}
" "
" ) return ( "
" "

" "📌 Zusätzliche Cross-Doc-Befunde (DPO / Staleness / CMP-Fingerprint)" "

" + "".join(cards) + "
" )