File size: 1,705 Bytes
7ff7119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""DomainCheck Protocol — every one of the 14 domain rules implements this.

Unification:
  * ``check_id``: stable identifier (debug, logging, registry lookup)
  * ``regulation``: ISA 240, GDPR Article 28, HU VAT Act §169, etc.
  * ``is_hu_specific``: True → only runs on Hungarian-jurisdiction documents
  * ``applies_to``: set of doc_types where the check runs, or ``{"*"}`` = anywhere
  * ``apply(extracted)``: returns a list of Risks based on the flat dict

``domain_checks/__init__.py`` lists all 14 in ``CHECK_REGISTRY``.
"""

from __future__ import annotations

from typing import Protocol, runtime_checkable

from graph.states.pipeline_state import Risk


@runtime_checkable
class DomainCheck(Protocol):
    """Protocol-level interface — every check class implements this."""

    check_id: str
    regulation: str
    is_hu_specific: bool
    applies_to: set[str]

    def apply(self, extracted: dict) -> list[Risk]: ...


def make_risk(
    description: str,
    severity: str,
    rationale: str,
    regulation: str,
    source_check_id: str,
) -> Risk:
    """Unified Risk builder for the domain checks."""
    return Risk(
        description=description,
        severity=severity,
        rationale=rationale,
        kind="domain_rule",
        regulation=regulation,
        source_check_id=source_check_id,
    )


def is_empty(value) -> bool:
    """Mirror of ``prototype-agentic/domain_checks.py:_is_empty``."""
    from utils.numbers import is_null_alias

    if value is None:
        return True
    if isinstance(value, str):
        return is_null_alias(value) or value.strip() == ""
    if isinstance(value, (list, dict)):
        return len(value) == 0
    return False