feat(archivar): User-Keyword-Override-Handler + Validierung + F5.3-Override (V2)

- _handle_user_keyword_override(room_id, user_text, override_ctx): validiert
  Freitext-Keyword (Button 4) und lernt mit source='user_corrected'
- _validate_user_keyword: 7-stufig (leer, Länge 3-50, Pure-Punctuation,
  URL/Datei-Fragmente, max 3 Wörter, Blocklist P-112)
- _normalize_user_keyword: lstrip '#', lower, Leerzeichen → '-'
- Abfang in _process_incoming: offene Override-Frage fängt Freitext ab
  (VOR Archivar-Routing, P-102-Klasse)
- check_auto_promotion(source='user_corrected') → False (Streitpunkt a)
- 18 Unit-Tests (Accept/Reject-Pfade, Normalisierung, F5.3-Deaktivierung)
This commit is contained in:
Bernd (Hermes)
2026-08-26 10:06:22 +02:00
parent ba47bb734e
commit dd59a185b4
3 changed files with 371 additions and 4 deletions
+11 -1
View File
@@ -1494,7 +1494,7 @@ class ArchivarState:
del self._routing_use_counter[keyword]
return self.save()
def check_auto_promotion(self, keyword: str, room_id: str) -> bool:
def check_auto_promotion(self, keyword: str, room_id: str, source: str = "") -> bool:
"""F5.2/F5.3: Prüfe ob ein (keyword, room)-Paar auto-promotet werden soll.
Schwelle: 5 Uses innerhalb 30 Tagen → True (Auto-Promotion zu permanent).
@@ -1504,13 +1504,23 @@ class ArchivarState:
markiert; alle weiteren Aufrufe liefern ``False`` — der Counter steigt
zwar weiter (für Telemetrie), aber es gibt keine erneute Promotion.
V2 (Butler-Lernkonzept, Streitpunkt a): Bei ``source='user_corrected'``
wird KEINE Auto-Promotion durchgeführt. Der User hat das Keyword bewusst
per Freitext gesetzt — die Maschine soll diese explizite Korrektur nicht
nachträglich "überstimmen" (keine versteckte zweite Meinung).
Args:
keyword: Das Keyword/Thema.
room_id: Der Raum.
source: Quellen-Tag ('red_flag' | 'butler' | 'user_corrected' | ...).
Bei 'user_corrected' wird immer False zurückgegeben.
Returns:
True beim Übergang auf >= 5 Uses (einmalig), sonst False.
"""
# V2: User-Korrekturen werden nie auto-promotet (Streitpunkt a).
if source == "user_corrected":
return False
pair = (keyword, room_id)
if pair in self._promoted_pairs:
return False