This commit is contained in:
Lars committed 2026-08-29 11:04:34 +02:00
1 parent 4f37991ad1
commit be11f82f84
39 files changed
+2490 -239

No files matched your search

+23 -7
View File
@@ -73,6 +73,22 @@ def is_maskable_label(label: str) -> bool:
return True
def is_registry_maskable_label(label: str) -> bool:
"""Confirmed names may be shorter than the detect gate. Not a semantic word list."""
core = (label or "").strip()
if len(core) < 2:
return False
if core.lower() in STRUCTURAL_UNMASKABLE:
return False
if TIME_RE.search(core):
return False
if re.fullmatch(r"user|assistant|self", core, re.IGNORECASE):
return False
if not re.search(r"[A-Za-zÀ-žÄÖÜäöüß]", core):
return False
return True
def _token_suffix(token: str) -> str:
raw = (token or "").upper()
return raw.split(":")[-1] if ":" in token else raw
@@ -111,7 +127,7 @@ def parse_aliases(raw) -> list[str]:
result: list[str] = []
for item in items:
label = (item or "").strip()
if not label or label.casefold() in seen or not is_maskable_label(label):
if not label or label.casefold() in seen or not is_registry_maskable_label(label):
continue
seen.add(label.casefold())
result.append(label)
@@ -189,7 +205,7 @@ def mapping_spellings(item: dict) -> list[str]:
def add(raw) -> None:
label = (raw or "").strip()
if not label or label.casefold() in seen or not is_maskable_label(label):
if not label or label.casefold() in seen or not is_registry_maskable_label(label):
return
seen.add(label.casefold())
result.append(label)
@@ -214,7 +230,7 @@ def masking_rows_from_confirmed(profile_id: str) -> list[dict]:
if not token or not canonical:
continue
for label in confirmed_match_labels(item):
if not is_maskable_label(label):
if not is_registry_maskable_label(label):
continue
rows.append(
{
@@ -274,7 +290,7 @@ def confirm_identity(
identity_id: str | None = None,
) -> dict:
label = normalize_label(canonical_label) or (canonical_label or "").strip()
if not label or not is_maskable_label(label):
if not label or not is_registry_maskable_label(label):
raise ValueError("empty_label")
kind = normalize_entity_type(entity_type)
if not kind:
@@ -360,7 +376,7 @@ def update_identity(
label = found["canonical_label"]
if canonical_label is not None:
label = normalize_label(canonical_label) or canonical_label.strip()
if not label or not is_maskable_label(label):
if not label or not is_registry_maskable_label(label):
raise ValueError("empty_label")
kind = found["entity_type"]
if entity_type is not None:
@@ -525,7 +541,7 @@ def purge_unmaskable(profile_id: str) -> int:
).fetchall()
for row in rows:
label = row["canonical_label"] or row["local_label"]
if is_maskable_label(label):
if is_registry_maskable_label(label):
continue
conn.execute("DELETE FROM identity_mappings WHERE id = ?", (row["id"],))
removed += 1
@@ -551,7 +567,7 @@ def coalesce_mappings(profile_id: str) -> int:
groups: dict[str, list[dict]] = {}
for row in rows:
core = normalize_label(row.get("canonical_label") or row.get("local_label") or "")
if not core or not is_maskable_label(core):
if not core or not is_registry_maskable_label(core):
conn.execute("DELETE FROM identity_mappings WHERE id = ?", (row["id"],))
merged += 1
continue