diff --git a/plugin/adapter.py b/plugin/adapter.py index ec510c2..f53d9b9 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -3173,9 +3173,20 @@ class RocketChatAdapter(BasePlatformAdapter): async def _cmd_hilfe(self, room_id: str, args: str) -> str: """::hilfe — Zeigt die Hilfeseite mit allen Befehlen.""" from archivar.inline_commands import build_help_text + + # P1-4: PresenceEngine-Werte lesen (mit _has_presence-Guard) + presence_enabled = None + current_status = "online" + _has_presence = hasattr(self, '_presence_engine') and self._presence_engine is not None + if _has_presence: + presence_enabled = self._presence_engine.is_enabled() + current_status = getattr(self._presence_engine, '_last_sent_status', 'online') or 'online' + return build_help_text( self._inline_commands, room_map_summary=self._room_map_summary, + presence_enabled=presence_enabled, + current_status=current_status, ) async def _cmd_status(self, room_id: str, args: str) -> str: @@ -3195,12 +3206,25 @@ class RocketChatAdapter(BasePlatformAdapter): butler_mode = getattr(room_map, 'butler_mode', 'unknown') onboarding_active = self.archivar._stats.get("onboarding_active", False) + # P1-4: PresenceEngine-Werte lesen (mit _has_presence-Guard) + presence_enabled = None + current_status = "online" + pulse_active = False + _has_presence = hasattr(self, '_presence_engine') and self._presence_engine is not None + if _has_presence: + presence_enabled = self._presence_engine.is_enabled() + current_status = getattr(self._presence_engine, '_last_sent_status', 'online') or 'online' + pulse_active = self._presence_engine._pulse_controller.is_running() + return build_status_text( room_count=room_count, archivar_active=archivar_active, butler_mode=butler_mode, onboarding_active=onboarding_active, room_map_summary=self._room_map_summary, + presence_enabled=presence_enabled, + current_status=current_status, + pulse_active=pulse_active, ) async def _cmd_reset(self, room_id: str, args: str) -> str: diff --git a/plugin/archivar/inline_commands.py b/plugin/archivar/inline_commands.py index 851375d..ebd69ed 100644 --- a/plugin/archivar/inline_commands.py +++ b/plugin/archivar/inline_commands.py @@ -211,12 +211,19 @@ class InlineCommandRegistry: # ── Help-Text-Generator ───────────────────────────────────────────────── -def build_help_text(registry: InlineCommandRegistry, room_map_summary: str = "") -> str: +def build_help_text( + registry: InlineCommandRegistry, + room_map_summary: str = "", + presence_enabled: Optional[bool] = None, + current_status: str = "online", +) -> str: """Baut die Hilfeseite mit ::-Befehlen und natürlichen Sprach-Befehlen. Args: registry: Die InlineCommandRegistry mit allen registrierten Befehlen. room_map_summary: Optionale Raum-Map-Übersicht für den Status-Teil. + presence_enabled: Ob die PresenceEngine aktiv ist (None = nicht verfügbar). + current_status: Aktueller Presence-Status ('online', 'away', 'busy'). Returns: Formatierte Hilfeseite als Markdown-String. @@ -290,6 +297,26 @@ def build_help_text(registry: InlineCommandRegistry, room_map_summary: str = "") lines.append("### 📋 Plugin-Status") lines.append("") + # P1-4: Status-Farben (Flughafen-Prinzip) — nur wenn PresenceEngine aktiv + if presence_enabled: + status_emoji = { + "online": "🟢 online (idle, verfügbar)", + "away": "🟡 away (Hintergrund-Task aktiv, Heartbeat pulsiert)", + "busy": "🔴 busy (verarbeitet Nachricht)", + } + lines.append("### 🚦 Status-Farben") + lines.append("") + lines.append( + "Der Bot zeigt seinen Status nach dem **Flughafen-Prinzip** an: " + "wie eine Ampel signalisiert er, ob er bereit (grün), beschäftigt " + "(rot) oder im Hintergrund aktiv (gelb) ist." + ) + lines.append("") + for status, label in status_emoji.items(): + marker = " ← aktuell" if status == current_status else "" + lines.append(f"- {label}{marker}") + lines.append("") + if room_map_summary: lines.append(room_map_summary) else: @@ -314,6 +341,9 @@ def build_status_text( butler_mode: str = "unknown", onboarding_active: bool = False, room_map_summary: str = "", + presence_enabled: Optional[bool] = None, + current_status: str = "online", + pulse_active: bool = False, ) -> str: """Baut die Status-Seite mit aktuellen Plugin-Informationen. @@ -323,6 +353,9 @@ def build_status_text( butler_mode: Butler-Modus ('cognitive', 'strict', 'off'). onboarding_active: Ob Onboarding gerade läuft. room_map_summary: Raum-Map-Übersicht. + presence_enabled: Ob die PresenceEngine aktiv ist (None = nicht anzeigen). + current_status: Aktueller Presence-Status ('online', 'away', 'busy'). + pulse_active: Ob der PulseController gerade pulsiert. Returns: Formatierte Status-Seite. @@ -342,6 +375,21 @@ def build_status_text( f"- **Onboarding:** {'🔄 Läuft' if onboarding_active else '✅ Abgeschlossen'}", ] + # P1-4: PresenceEngine-Info (nur wenn presence_enabled explizit gesetzt) + if presence_enabled is not None: + status_labels = { + "online": "🟢 online (idle, verfügbar)", + "away": "🟡 away (Hintergrund-Task aktiv)", + "busy": "🔴 busy (verarbeitet Nachricht)", + } + pulse_label = "💓 aktiv" if pulse_active else "⏸️ inaktiv" + if presence_enabled: + lines.append(f"- **PresenceEngine:** ✅ Aktiv") + lines.append(f"- **Aktueller Status:** {status_labels.get(current_status, current_status)}") + lines.append(f"- **Pulse:** {pulse_label}") + else: + lines.append(f"- **PresenceEngine:** ❌ Inaktiv") + if room_map_summary: lines.append("") lines.append(room_map_summary) diff --git a/plugin/archivar/tests/test_r5_inline_commands.py b/plugin/archivar/tests/test_r5_inline_commands.py index 20eb3d0..39c1c2c 100644 --- a/plugin/archivar/tests/test_r5_inline_commands.py +++ b/plugin/archivar/tests/test_r5_inline_commands.py @@ -1092,3 +1092,142 @@ class TestCommandHandlersMocked: assert handler is not None result = await handler("room1", "") assert "hermes update" in result + + +# ═══════════════════════════════════════════════════════════════════════════ +# P1-4: Status-Farben in ::hilfe und ::status +# ═══════════════════════════════════════════════════════════════════════════ + + +class TestHelpTextPresenceColors: + """P1-4: build_help_text zeigt Status-Farben-Sektion wenn presence_enabled.""" + + def test_help_text_includes_status_colors_when_presence_enabled(self): + """presence_enabled=True → 'Status-Farben' Sektion erscheint.""" + from archivar.inline_commands import InlineCommandRegistry, build_help_text + + registry = InlineCommandRegistry() + text = build_help_text(registry, presence_enabled=True, current_status="online") + + assert "Status-Farben" in text, ( + f"Status-Farben Sektion fehlt:\n{text}" + ) + assert "online" in text + assert "away" in text + assert "busy" in text + # Flughafen-Prinzip erklärt + assert "flughafen" in text.lower() or "ampel" in text.lower(), ( + f"Flughafen-Prinzip nicht erklärt:\n{text}" + ) + + def test_help_text_no_status_colors_when_presence_disabled(self): + """presence_enabled=False → keine Status-Farben Sektion.""" + from archivar.inline_commands import InlineCommandRegistry, build_help_text + + registry = InlineCommandRegistry() + text = build_help_text(registry, presence_enabled=False) + + assert "Status-Farben" not in text, ( + f"Status-Farben Sektion sollte nicht erscheinen:\n{text}" + ) + + def test_help_text_no_status_colors_when_presence_none(self): + """presence_enabled=None (default) → keine Status-Farben Sektion.""" + from archivar.inline_commands import InlineCommandRegistry, build_help_text + + registry = InlineCommandRegistry() + text = build_help_text(registry) + + assert "Status-Farben" not in text + + +class TestStatusTextPresenceInfo: + """P1-4: build_status_text zeigt PresenceEngine-Info wenn presence_enabled.""" + + def test_status_text_includes_presence_info_when_enabled(self): + """presence_enabled=True → PresenceEngine + Status + Pulse Zeilen.""" + from archivar.inline_commands import build_status_text + + text = build_status_text( + room_count=3, + archivar_active=True, + butler_mode="cognitive", + presence_enabled=True, + current_status="online", + pulse_active=True, + ) + + assert "PresenceEngine" in text, ( + f"PresenceEngine-Zeile fehlt:\n{text}" + ) + assert "Aktiv" in text # ✅ Aktiv + assert "online" in text, ( + f"Aktueller Status fehlt:\n{text}" + ) + assert "aktiv" in text.lower(), ( + f"Pulse-Info fehlt:\n{text}" + ) + + def test_status_text_includes_presence_info_when_disabled(self): + """presence_enabled=False → PresenceEngine ❌ Inaktiv.""" + from archivar.inline_commands import build_status_text + + text = build_status_text( + room_count=0, + archivar_active=False, + butler_mode="off", + presence_enabled=False, + current_status="online", + pulse_active=False, + ) + + assert "PresenceEngine" in text + assert "Inaktiv" in text + + def test_status_text_no_presence_info_when_default(self): + """presence_enabled=False (default) → keine PresenceEngine-Zeile.""" + from archivar.inline_commands import build_status_text + + text = build_status_text( + room_count=1, + archivar_active=True, + butler_mode="strict", + ) + + assert "PresenceEngine" not in text, ( + f"PresenceEngine sollte nicht erscheinen (default):\n{text}" + ) + + def test_status_text_shows_away_status(self): + """current_status='away' → 🟡 away im Status-Text.""" + from archivar.inline_commands import build_status_text + + text = build_status_text( + room_count=2, + archivar_active=True, + butler_mode="cognitive", + presence_enabled=True, + current_status="away", + pulse_active=True, + ) + + assert "away" in text, ( + f"away-Status fehlt:\n{text}" + ) + + def test_status_text_shows_busy_status(self): + """current_status='busy' → 🔴 busy im Status-Text.""" + from archivar.inline_commands import build_status_text + + text = build_status_text( + room_count=2, + archivar_active=True, + butler_mode="cognitive", + presence_enabled=True, + current_status="busy", + pulse_active=False, + ) + + assert "busy" in text, ( + f"busy-Status fehlt:\n{text}" + )