feat(F557): Emoji-Number Fallback fuer nicht-interactive Clients @implements: [F-557]
- button_builder.py: _is_numeric_choice() Helper (Inverse der Emoji-Nummer-Generierung)
erkennt "1", Emoji-Keycap "1", "1.", "1)", "1 rueber", "Option 1" -> 1-basierter Index;
"0"/"11"/"99" + Multi-Wahl ("1 und 2") -> None
- adapter.py: is_pending_clarify_answer + Plain-Digit-Clarify-Block + Move-Request-Intercept
von isdigit()/expliziten Listen auf _is_numeric_choice() umgestellt
- Fallback IMMER aktiv (keine Client-Type-Detection, Rainer 2.4)
- test_f557_numeric_choice.py: 29 Tests (Rainer 4: 5 Test-Pflichten + Edge-Case-Matrix)
- KEINE Core-Aenderungen (nur Plugin-Layer)
This commit is contained in:
+46
-16
@@ -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:<id>:<idx> / CLARIFY:<id>::<idx>)
|
||||
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)
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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"]))
|
||||
Reference in New Issue
Block a user