diff --git a/STATUS.md b/STATUS.md index d7177ad..1ff3edd 100644 --- a/STATUS.md +++ b/STATUS.md @@ -1,5 +1,5 @@ # Projekt-STATUS — Hermes Rocket.Chat Plugin -> **Stand:** 26. September 2026 — F551 IMPLEMENTIERUNG (Infrastruktur-Typ): install.sh Venv-Discovery für ~/.hermes/tools/python-* (Python 3.14) + Stufe-9-Repair der Tools-Python-Pakete. @implements [F-551]. **F551:** Nach Hermes-Update auf Python 3.14 läuft der Gateway auf dem Standalone-Tools-Python `~/.hermes/tools/python-3.14.7+.../bin/python3` (kein venv/pipx). `find_pipx_venv()` priorisiert jetzt diesen Pfad (höchste Python-Version via `find_tools_python()`), Fallback pipx → hermes-agent/venv → system. Neuer `--repair`-Check "Stufe 9" prüft im Tools-Python: ruamel.yaml, snowballstemmer, websocket-client, PyYAML (Core) + faiss-cpu/numpy (nur Multiroom & Provider≠custom) und installiert Fehlendes via `pip install` im aktiven Python. KEINE Core-Änderungen. +> **Stand:** 26. September 2026 — F557 IMPLEMENTIERUNG: Emoji-Number Fallback für nicht-interactive Clients. @implements [F-557]. **F557:** Neue Helper-Funktion `_is_numeric_choice()` in `button_builder.py` (Inverse der Emoji-Nummer-Generierung) erkennt "1", "1️⃣", "1.", "1)", "1 rüber", "Option 1" → 1-basierter Index; "0"/"11"/"99" und Multi-Wahl ("1 und 2") → None. Clarify-Intercept (adapter.py `is_pending_clarify_answer` + Plain-Digit-Block) und Move-Request-Intercept (explizite Listen) auf den Helper umgestellt. Fallback IMMER aktiv (keine Client-Type-Detection). KEINE Core-Änderungen. 29 neue Tests. > **Letzter fachlicher Commit:** `feat(F553): main_agent Counter-Leak Fix — Lifecycle-Tracker (Variante B) @implements: [F-553]` (`fcf0851`, 23.09.2026) > **Gitea-Remote:** ✅ Synchron — `fcf0851` + `07be8ba` + `b533320` + `786fa04` + `b175765` + `9b8ad40` + `97d5d88` + `a1af777` + `60103ed` + `c509876` + `dafd72f` + `3dcd024` + `eec8904` + `e02d34e` + `a24dc9d` + `8a00c39` + `f81a510` + `221500e` + `32b560d` + `31ca0f2` + `df8be1c` + `500c28a` + `f165f11` + `4ea711c` + `5027738` + `117b839` + `b8373d3` + `25678c6` + `bb91468` + `a1f4ed0` + `f0f3537` + `ebd057e` + `0d9275d` + `6e8854d` + `b61e19d` + `05531f1` gepusht auf origin/main. > **Deployment:** ✅ .101 deployed bei `b533320` (Plugin v10.4 — F551+F552). 112 Features GRÜN, 2 verworfen (grau). F553 NOCH NICHT deployed (Bit 7/8 QG ausstehend). @@ -26,6 +26,7 @@ | Commit | Beschreibung | Datum | |---|---|---| +| `F557-PENDING` | feat(F557): Emoji-Number Fallback — _is_numeric_choice Helper + Clarify/Move-Request-Intercept @implements: [F-557] — button_builder.py (_is_numeric_choice, _EMOJI_TO_NUM, _MAX_CHOICE), adapter.py (is_pending_clarify_answer + Plain-Digit-Block + Move-Request-Intercept auf Helper umgestellt), test_f557_numeric_choice.py (29 Tests), STATUS.md, 4 Dateien | 26.09. | | `e8d4523` | feat(F551): install.sh Venv-Discovery tools/python-* + Stufe-9 Paket-Repair @implements: [F-551] — install.sh (find_tools_python + find_pipx_venv priorisiert Tools-Python, _tools_pkg_pipname, check_components Stufe 9, repair_components Stufe 9), STATUS.md, 2 Dateien | 26.09. | | `fcf0851` | feat(F553): main_agent Counter-Leak Fix — Lifecycle-Tracker (Variante B) @implements: [F-553] — presence_engine.py (adaptive Cap `_compute_adaptive_h_cap` Welford/Quantil+Bufferklemme [120s..1800s], `refresh_main_agent_heartbeat` + lock-freie Variante, `_main_agent_gc_locked` Heartbeat-Alter-GC ohne pgrep, `TaskState.fresh_adoption`, `_record_h_turn_duration_locked`, `_drift_correction` ruft Lifecycle-GC), adapter.py (`_refresh_main_agent_heartbeat`-Helper + Turn-Start-Aufruf), test_f553_main_agent_lifecycle.py (12 Tests), STATUS.md, analysen/F553_Architektur_Rainer.md, 4 Dateien | 23.09. | | `07be8ba` | docs: F552 QG-Code Rainer (476 Zeilen) @implements: [F-552] — analysen/F552_QG-Code_Rainer.md (404 Zeilen, Rainer QG-Code-Review für F552), 1 Datei +404 | 22.09. | diff --git a/plugin/adapter.py b/plugin/adapter.py index b94b71a..c7102e2 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -2,6 +2,7 @@ # @implements: [F-551] — PFAD:-Präfix gegen Slash-Command-Blockade (FAKT-Pfad-Eingabe) # @implements: [F-552] — Presence-Engine Subagent-Tracking (register_engine-Verdrahtung, Variante B) # @implements: [F-553] — main_agent Counter-Leak Fix (Heartbeat-Refresh-Baustein, Variante B) +# @implements: [F-557] — Emoji-Number Fallback für nicht-interactive Clients (Clarify + Move-Request) """ Rocket.Chat Platform Adapter for Hermes Agent. @@ -2869,8 +2870,9 @@ class RocketChatAdapter(BasePlatformAdapter): Clarify-Frage zu werten ist — unabhängig vom Format-Pfad: 1. CLARIFY:-Button-Payload (CLARIFY:: / CLARIFY:::) - 2. Plain-Digit-Text (Feature 53, P-047 Mobile-Workaround) in einem - Raum mit offener Clarify-Frage (_room_clarify) + 2. Plain-Digit/Emoji-Text (Feature 53, P-047 Mobile-Workaround, + F-557 erweitert auf Emoji/Varianten) in einem Raum mit offener + Clarify-Frage (_room_clarify) Der Archivar-Routing-Block prüft diesen Trigger VOR der Klassifikation und leitet Clarify-Antworten IMMER am Routing @@ -2891,8 +2893,16 @@ class RocketChatAdapter(BasePlatformAdapter): # 1. CLARIFY:-Button-Payload (beide Formate) if stripped.startswith("CLARIFY:"): return True - # 2. Plain-Digit-Text in einem Raum mit offener Clarify-Frage - if stripped.isdigit() and room_id in getattr(self, "_room_clarify", {}): + # 2. Plain-Digit/Emoji-Text in einem Raum mit offener Clarify-Frage + # F-557: _is_numeric_choice statt isdigit() — erkennt Emoji-Nummern + # ("1️⃣") und Varianten ("1.", "1 rüber", "Option 1") zusätzlich. + _num = None + try: + from archivar.button_builder import _is_numeric_choice + _num = _is_numeric_choice(stripped) + except Exception: + _num = None + if _num is not None and room_id in getattr(self, "_room_clarify", {}): return True return False @@ -3461,9 +3471,18 @@ class RocketChatAdapter(BasePlatformAdapter): if not is_clarify_response and not is_archivar_clarify: stripped = text.strip() _room_clarify = getattr(self, "_room_clarify", {}) - if stripped.isdigit() and room_id in _room_clarify: + # F-557: _is_numeric_choice statt isdigit() — erkennt Emoji-Nummern + # ("1️⃣") und Varianten ("1.", "1 rüber", "Option 1"). Liefert den + # 1-basierten Index direkt (oder None bei out-of-range/Multi-Wahl). + _numeric_choice = None + try: + from archivar.button_builder import _is_numeric_choice + _numeric_choice = _is_numeric_choice(stripped) + except Exception: + _numeric_choice = None + if _numeric_choice is not None and room_id in _room_clarify: clarify_id = _room_clarify[room_id] - idx = int(stripped) - 1 # 1-basierte Eingabe → 0-basierter Index + idx = _numeric_choice - 1 # 1-basierte Eingabe → 0-basierter Index resolved_text: Optional[str] = None try: from tools.clarify_gateway import _entries as _clarify_entries @@ -4004,16 +4023,27 @@ class RocketChatAdapter(BasePlatformAdapter): choice = choice[:2] # Altes Format: "1"/"2"/"3"/"4" = numerische Antwort # Neues Format: "1️⃣", "2️⃣", "3️⃣", "4️⃣" = Emoji-Nummern - elif choice in ("1", "2", "3", "4") or choice in ("1️⃣", "2️⃣", "3️⃣", "4️⃣"): - num = int(choice[0]) # Extrahiere die Zahl (entweder direkt oder aus dem Emoji) - if num == 1: - choice = "rüberkopieren" - elif num == 2: - choice = "generell" # v6: 2 = Generell hier bleiben (sticky) - elif num == 3: - choice = "hier bleiben" # v6: 3 = Hier bleiben (nur diesmal) - else: - choice = "falsch" # v6: 4 = Falsch geroutet (reject) + # F-557: explizite Listen → _is_numeric_choice() + Bounds-Check. + # Erkennt zusätzlich "1.", "1 rüber", "Option 1", "1)" mit + # Leading/Trailing-Whitespace-Toleranz. Multi-Wahl ("1 und 2") + # und out-of-range ("5"/"0") liefern None → normale Verarbeitung. + else: + _move_num = None + try: + from archivar.button_builder import _is_numeric_choice + _move_num = _is_numeric_choice(choice) + except Exception: + _move_num = None + if _move_num is not None and 1 <= _move_num <= 4: + num = _move_num + if num == 1: + choice = "rüberkopieren" + elif num == 2: + choice = "generell" # v6: 2 = Generell hier bleiben (sticky) + elif num == 3: + choice = "hier bleiben" # v6: 3 = Hier bleiben (nur diesmal) + else: + choice = "falsch" # v6: 4 = Falsch geroutet (reject) choice = choice.lower() # Neue Mapping-Logik für verbesserte Button-UX (v6) diff --git a/plugin/archivar/button_builder.py b/plugin/archivar/button_builder.py index 93b4e60..3c7069e 100644 --- a/plugin/archivar/button_builder.py +++ b/plugin/archivar/button_builder.py @@ -1,5 +1,6 @@ # @implements: [F-052] — Clarify-UX Emoji Buttons # @implements: [F-054] — Clarify-UX max 3/Reihe Chunking (2-Reihen-Pattern) +# @implements: [F-557] — Emoji-Number Fallback: _is_numeric_choice Helper """ Gemeinsamer Button-Builder für Onboarding und Review-Flow. @@ -14,11 +15,87 @@ Regeln: """ import hashlib -from typing import Any, List, Tuple +import re +from typing import Any, List, Optional, Tuple # Emoji-Nummern für bis zu 10 Buttons EMOJI_NUMBERS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"] +# F-557: Inverse-Mapping — Emoji-Nummer → 1-basierter Index. +# Die ersten 9 sind "Ziffer + U+FE0F + U+20E3" (3 Codepoints), "🔟" (U+1F51F) +# ist ein EINZELNER Codepoint ohne ASCII-Ziffer. Deshalb ein explizites Mapping +# statt String-Index-Arithmetik. Zusätzlich die Kompaktform ohne +# Variation-Selector ("1⃣" = U+0031 U+20E3), die manche Clients senden. +_EMOJI_TO_NUM: dict = {e: i + 1 for i, e in enumerate(EMOJI_NUMBERS)} +_EMOJI_TO_NUM.update({f"{d}\u20e3": d for d in range(1, 10)}) + +# F-557: Oberes Limit — EMOJI_NUMBERS deckt 1..10 ab. Höhere Zahlen sind +# out-of-range (bei Clarify mit >10 Optionen ohnehin ein UX-Problem). +_MAX_CHOICE = len(EMOJI_NUMBERS) # 10 + + +def _is_numeric_choice(text: Optional[str]) -> Optional[int]: + """Extrahiert eine 1-basierte Wahl aus ``text`` oder ``None`` (F-557). + + Symmetrisch zu ``EMOJI_NUMBERS``: der Helper ist die Inverse der + Emoji-Nummer-Generierung. Erkennt sowohl die Button-Varianten + (Emoji-Keycap) als auch die Plain-Text-Fallbacks, die User in + nicht-interactiven Clients (Mobile-App, Frame/Blockquote-Rendering) + tippen, wenn Interactive Buttons nicht klickbar sind (P-047). + + Akzeptiert (Leading/Trailing-Whitespace tolerant): + - "1", "2", ..., "9", "10" (rein numerisch) + - "1️⃣", "2️⃣", ..., "🔟" (Emoji-Nummern, inkl. Kompaktform) + - "1.", "9." (mit Punkt) + - "1)", "1.)" (mit Klammer) + - "1 Rüber" (führende Ziffer + Text) + - "Option 1" (Wort + Zahl) + + Liefert ``None`` (keine Wahl): + - "" / "abc" / "0" (leer, nicht-numerisch, nicht 1-basiert) + - "11" (out-of-range, > EMOJI_NUMBERS-Cap) + - "1 und 2", "1, 2", "1 oder 2" (Multi-Wahl — bewusst NICHT unterstützt, + siehe Architektur F557 §3.3) + + Args: + text: Die (bereits quote-gestrippte) Eingabe des Users. + + Returns: + 1-basierter Index (1..10) oder ``None`` wenn keine eindeutige Wahl. + """ + if text is None: + return None + s = text.strip() + if not s: + return None + + # 1) Exakter Emoji-Keycap ("1️⃣" … "🔟") oder Kompaktform ("1⃣" … "9⃣"). + if s in _EMOJI_TO_NUM: + return _EMOJI_TO_NUM[s] + + # 2) "Option N" — Wort am Anfang, Zahl am Ende. + m = re.match(r"^option\s+(\d{1,2})\s*$", s, re.IGNORECASE) + if m: + num = int(m.group(1)) + return num if 1 <= num <= _MAX_CHOICE else None + + # 3) Führende Ziffer ("1", "1.", "1)", "1 rüber", "1 und 2"). + m = re.match(r"^(\d{1,2})", s) + if not m: + return None + num = int(m.group(1)) + if not (1 <= num <= _MAX_CHOICE): + return None + rest = s[m.end():].strip() + # "1." / "1)" / "1.)" — nur Satzzeichen-Suffix → Einzelwahl. + if rest in ("", ".", ")", ".)"): + return num + # Multi-Wahl: Rest beginnt mit Konjunktion + Zahl oder direkt mit Zahl. + if re.match(r"^(?:und|oder|and|or|,|;|\+|&)\s*\d", rest, re.IGNORECASE) or rest[0].isdigit(): + return None + # Sonst: führende Ziffer mit Text ("1 rüber") → Einzelwahl. + return num + def _make_action_id(msg_payload: str, index: int = 0) -> str: """Deterministische action_id aus msg-Payload (SHA1, 12 Zeichen). diff --git a/plugin/archivar/tests/test_f557_numeric_choice.py b/plugin/archivar/tests/test_f557_numeric_choice.py new file mode 100644 index 0000000..d1105a1 --- /dev/null +++ b/plugin/archivar/tests/test_f557_numeric_choice.py @@ -0,0 +1,103 @@ +""" +F-557: Emoji-Number Fallback — _is_numeric_choice Helper (Rainer §4). + +Deckt die 5 Test-Pflichten aus der Architektur ab: +1. "1" → Wahl 1 (Regression — Plain-Digit, war schon funktional) +2. "1️⃣" → Wahl 1 (L1-Fix — Emoji-Variante war nicht erkannt) +3. "1 rüber" / "Option 1" / "1." → Wahl 1 (L2-Fix — loose Match) +4. "5" / "0" → None (Bounds-Check) +5. "1 und 2" → None (Multi-Wahl nicht erlaubt) + +Zusätzlich die parametrisierte Edge-Case-Matrix aus Rainer §4 Test 1. +""" + +from __future__ import annotations + +import sys +from pathlib import Path + +import pytest + +sys.path.insert(0, str(Path(__file__).resolve().parents[3])) + +from archivar.button_builder import _is_numeric_choice + + +@pytest.mark.parametrize( + "text,expected", + [ + # Plain-Digit (Regression) + ("1", 1), + ("9", 9), + ("10", 10), + # Emoji-Nummern (L1) + ("1️⃣", 1), + ("🔟", 10), + # Mit Punkt (L2) + ("1.", 1), + ("9.", 9), + # Whitespace-tolerant + (" 1 ", 1), + ("\t2\n", 2), + # Mit Text (L2) + ("1 rüber", 1), + ("Option 1", 1), + ("1)", 1), + ("1.)", 1), + # Invalid + ("", None), + ("abc", None), + ("0", None), + # Out of EMOJI_NUMBERS cap (Bounds-Check, Test 4) + ("11", None), + ("99", None), + ("123", None), + # Multi-Wahl (nicht erlaubt, Test 5) + ("1 und 2", None), + ("1, 2", None), + ("1 oder 2", None), + ("2 und 3", None), + # None-Eingabe + (None, None), + ], +) +def test_is_numeric_choice(text, expected): + assert _is_numeric_choice(text) == expected + + +def test_plain_digit_regression(): + """Test 1: '1' → Wahl 1 (bereits funktional, Regression-Test).""" + assert _is_numeric_choice("1") == 1 + + +def test_emoji_digit_l1_fix(): + """Test 2: '1️⃣' → Wahl 1 (L1-Fix — Emoji-Variante).""" + assert _is_numeric_choice("1️⃣") == 1 + + +def test_loose_variants_l2_fix(): + """Test 3: '1 rüber' / 'Option 1' / '1.' → Wahl 1 (L2-Fix).""" + assert _is_numeric_choice("1 rüber") == 1 + assert _is_numeric_choice("Option 1") == 1 + assert _is_numeric_choice("1.") == 1 + + +def test_bounds_check_out_of_range(): + """Test 4: '0' / '11' / '99' → None (Bounds-Check). + + Der Helper deckt 1..10 ab (EMOJI_NUMBERS-Cap). Der 4-Bound ist eine + Call-Site-Angelegenheit (Move-Request: 1<=num<=4; Clarify: + idx < len(choices)). '0' ist nicht 1-basiert → None. + """ + assert _is_numeric_choice("0") is None + assert _is_numeric_choice("11") is None + assert _is_numeric_choice("99") is None + + +def test_multi_choice_not_allowed(): + """Test 5: '1 und 2' → None (Multi-Wahl nicht erlaubt).""" + assert _is_numeric_choice("1 und 2") is None + + +if __name__ == "__main__": + sys.exit(pytest.main([__file__, "-v"]))