File size: 706 Bytes
b4abb69
c8a2428
 
 
2909950
c8a2428
eae09d2
bc3d2d2
eae09d2
 
 
 
 
 
 
 
 
 
 
 
 
bcde322
2909950
 
 
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
# src/explainability.py
# -----------------------------------------------------------------------------
# Minimal helpers kept for guideline rerun logic (hash-based staleness).
# -----------------------------------------------------------------------------

from __future__ import annotations
import hashlib
import re

def normalize_text(s: str) -> str:
    return re.sub(r"\s+", " ", (s or "").strip())

def text_hash(s: str) -> str:
    s_norm = normalize_text(s)
    return hashlib.sha256(s_norm.encode("utf-8")).hexdigest()[:16]

def is_stale(current_text: str, baseline_hash: str | None) -> bool:
    if not baseline_hash:
        return False
    return text_hash(current_text) != baseline_hash