feat: V8.5 — R5 ::-Inline-Befehle (13 Befehle: 7 Standard + 6 RC-spezifisch) + Onboarding-Fix (Plugin-onboarding vor generisch)
This commit is contained in:
+570
-1
@@ -23,7 +23,6 @@ import threading
|
|||||||
import time
|
import time
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.request
|
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
|
|
||||||
@@ -794,6 +793,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
# neu gebaut. Der Gateway-Core rendert chat_topic als "**Channel Topic:**"
|
# neu gebaut. Der Gateway-Core rendert chat_topic als "**Channel Topic:**"
|
||||||
# im System-Prompt — der Agent sieht die Raum-Map also BEI JEDEM START.
|
# im System-Prompt — der Agent sieht die Raum-Map also BEI JEDEM START.
|
||||||
self._room_map_summary: str = ""
|
self._room_map_summary: str = ""
|
||||||
|
# R5: Inline-Command-Registry für ::-Befehle
|
||||||
|
from archivar.inline_commands import InlineCommandRegistry
|
||||||
|
self._inline_commands = InlineCommandRegistry()
|
||||||
|
self._register_inline_commands()
|
||||||
|
|
||||||
def _build_room_map_summary(self) -> str:
|
def _build_room_map_summary(self) -> str:
|
||||||
"""Baut eine menschenlesbare Raum-Map-Übersicht für den System-Prompt.
|
"""Baut eine menschenlesbare Raum-Map-Übersicht für den System-Prompt.
|
||||||
@@ -1534,6 +1537,17 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
room_type = self._room_info.get(room_id, {}).get("type", "unknown")
|
room_type = self._room_info.get(room_id, {}).get("type", "unknown")
|
||||||
logger.info("[rocketchat] Message from %s in %s [%s]: %s", username, room_name, room_type, text[:80])
|
logger.info("[rocketchat] Message from %s in %s [%s]: %s", username, room_name, room_type, text[:80])
|
||||||
|
|
||||||
|
# ── R5: Inline-Command-Erkennung (VOR Onboarding + Hermes-Dispatch) ──
|
||||||
|
# ::-Befehle und natürliche Hilfeseiten-Anfragen müssen VOR dem
|
||||||
|
# generischen Hermes-Agent-Onboarding erkannt werden.
|
||||||
|
inline_handled = await self._handle_inline_command(text, room_id, room_name, username)
|
||||||
|
if inline_handled:
|
||||||
|
logger.debug("[rocketchat] R5: Inline-Command verarbeitet — skipping agent dispatch")
|
||||||
|
routing_counter.increment('inline_command_handled')
|
||||||
|
logger.info("ROUTING BYPASS: reason=inline_command_handled, origin_room=%s", room_id)
|
||||||
|
return
|
||||||
|
# ── Ende R5 Inline-Command-Erkennung ────────────────────────────────
|
||||||
|
|
||||||
# ── B5v6.5: Conversation History — User-Nachricht aufzeichnen ──
|
# ── B5v6.5: Conversation History — User-Nachricht aufzeichnen ──
|
||||||
if _MULTIROOM() and self._conversation_history is not None:
|
if _MULTIROOM() and self._conversation_history is not None:
|
||||||
await self._conversation_history.add(room_id, "user", text)
|
await self._conversation_history.add(room_id, "user", text)
|
||||||
@@ -1581,6 +1595,42 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
return
|
return
|
||||||
# ── Ende A1b Lazy-Onboarding ─────────────────────────────────────
|
# ── Ende A1b Lazy-Onboarding ─────────────────────────────────────
|
||||||
|
|
||||||
|
# ── Thema B: Onboarding-Guard — Plugin-onboarding vor generischem Hermes-onboarding ──
|
||||||
|
# Wenn Onboarding aktiv ist und die Nachricht aus einem Raum kommt,
|
||||||
|
# der NICHT in der room-map.json steht und NICHT der Operator-DM ist,
|
||||||
|
# dann die Nachricht abfangen. Verhindert dass das generische
|
||||||
|
# Hermes-Agent-Onboarding (Profile, Skills, Cronjobs) das
|
||||||
|
# Plugin-Onboarding (Raum-Interview) übersteuert.
|
||||||
|
if (
|
||||||
|
_MULTIROOM()
|
||||||
|
and self.archivar is not None
|
||||||
|
and self.archivar._stats.get("onboarding_active", False)
|
||||||
|
and room_type != "d"
|
||||||
|
):
|
||||||
|
operator_room = self._onboarding_state.get("operator_room_id", "")
|
||||||
|
# Prüfe ob der Raum in der room-map.json steht
|
||||||
|
room_in_map = (
|
||||||
|
self.archivar._room_map is not None
|
||||||
|
and room_id in self.archivar._room_map.rooms
|
||||||
|
)
|
||||||
|
if not room_in_map and room_id != operator_room:
|
||||||
|
# Raum ist unbekannt und Onboarding läuft → Nachricht abfangen
|
||||||
|
logger.info(
|
||||||
|
"[rocketchat] Thema B: Onboarding-Guard — Nachricht aus unbekanntem Raum "
|
||||||
|
"während Onboarding abgefangen: room=%s, name=%s",
|
||||||
|
room_id[:12], room_name,
|
||||||
|
)
|
||||||
|
await self._post_message_with_retry(
|
||||||
|
room_id,
|
||||||
|
"🔄 Ich richte mich gerade ein — einen Moment bitte. "
|
||||||
|
"Das Onboarding-Interview läuft in deinem DM-Kanal. "
|
||||||
|
"Sobald ich fertig bin, bin ich für dich da!"
|
||||||
|
)
|
||||||
|
routing_counter.increment('onboarding_guard_blocked')
|
||||||
|
logger.info("ROUTING BYPASS: reason=onboarding_guard_blocked, origin_room=%s", room_id)
|
||||||
|
return
|
||||||
|
# ── Ende Thema B Onboarding-Guard ────────────────────────────────────
|
||||||
|
|
||||||
# ── CLARIFY Response Handling ───────────────────────────────────
|
# ── CLARIFY Response Handling ───────────────────────────────────
|
||||||
# Handle CLARIFY button responses: CLARIFY:<clarify_id>:<choice> or CLARIFY:<clarify_id>:other
|
# Handle CLARIFY button responses: CLARIFY:<clarify_id>:<choice> or CLARIFY:<clarify_id>:other
|
||||||
# V8.2.1 A2: Handle ARCHIVAR_CLARIFY (Nachklärung) responses
|
# V8.2.1 A2: Handle ARCHIVAR_CLARIFY (Nachklärung) responses
|
||||||
@@ -2597,6 +2647,525 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
except Exception as e2:
|
except Exception as e2:
|
||||||
logger.error("[rocketchat] BUTTON_CLICK text fallback also failed: %s", e2)
|
logger.error("[rocketchat] BUTTON_CLICK text fallback also failed: %s", e2)
|
||||||
|
|
||||||
|
# ── R5: Inline-Command-Handler ────────────────────────────────────────
|
||||||
|
|
||||||
|
def _register_inline_commands(self) -> None:
|
||||||
|
"""Registriert alle ::-Befehle in der InlineCommandRegistry."""
|
||||||
|
# ── Standard-Hermes-Befehle (:: als Variante) ──────────────────
|
||||||
|
self._inline_commands.register(
|
||||||
|
"sethome", self._cmd_sethome,
|
||||||
|
help_text="Setzt den Heimatraum (Alternative zu /sethome)",
|
||||||
|
description="Setzt den aktuellen Raum als Heimatraum. "
|
||||||
|
"Der Heimatraum ist der primäre Raum für Catch-All-Nachrichten.",
|
||||||
|
category="Standard",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"reset", self._cmd_reset,
|
||||||
|
help_text="Setzt den Plugin-Status zurück (Alternative zu /reset)",
|
||||||
|
description="Setzt den Plugin-Status zurück (Onboarding, Session-Präferenzen).",
|
||||||
|
category="Standard",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"busy", self._cmd_busy,
|
||||||
|
help_text="Zeigt/steuert den Busy-Status (::Variante von /busy)",
|
||||||
|
description="Subcommands: queue <text>, steer <text>, status. "
|
||||||
|
"Steuert was passiert während der Agent arbeitet.",
|
||||||
|
category="Standard",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"allowalways", self._cmd_allowalways,
|
||||||
|
help_text="Verwaltet die Allow-Always-Liste (::Variante von /allow-always)",
|
||||||
|
description="Zeigt oder erweitert die Allow-Always-Liste für Skills.",
|
||||||
|
category="Standard",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"commands", self._cmd_commands,
|
||||||
|
help_text="Listet alle ::-Befehle (::Variante von /commands)",
|
||||||
|
description="Zeigt die vollständige Hilfeseite mit allen Befehlen.",
|
||||||
|
category="Info",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"restart", self._cmd_restart,
|
||||||
|
help_text="Löst Gateway-Neustart aus (::Variante von /restart)",
|
||||||
|
description="Startet den Hermes-Gateway-Dienst neu.",
|
||||||
|
category="Gateway",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"update", self._cmd_update,
|
||||||
|
help_text="Zeigt Update-Informationen (::Variante von /update)",
|
||||||
|
description="Zeigt wie Hermes auf die neueste Version aktualisiert wird.",
|
||||||
|
category="Gateway",
|
||||||
|
)
|
||||||
|
|
||||||
|
# ── RC-Plugin-spezifische Befehle ──────────────────────────────
|
||||||
|
self._inline_commands.register(
|
||||||
|
"setfakt", self._cmd_setfakt,
|
||||||
|
help_text="Ändert den FAKT-Speicherort",
|
||||||
|
description="Öffnet den FAKT-Speicherort-Dialog. "
|
||||||
|
"Du kannst den Pfad ändern, wo FAKT-Nachrichten persistiert werden.",
|
||||||
|
category="Konfiguration",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"hilfe", self._cmd_hilfe,
|
||||||
|
help_text="Zeigt diese Hilfeseite",
|
||||||
|
description="Zeigt alle verfügbaren ::-Befehle und "
|
||||||
|
"natürlichen Sprach-Befehle an.",
|
||||||
|
category="Hilfe",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"status", self._cmd_status,
|
||||||
|
help_text="Zeigt aktuellen Plugin-Status",
|
||||||
|
description="Zeigt Räume, Archivar-Status, Butler-Modus und "
|
||||||
|
"Onboarding-Status an.",
|
||||||
|
category="Hilfe",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"multiroom", self._cmd_multiroom,
|
||||||
|
help_text="Multi-Room-Agent aktivieren/deaktivieren/Status",
|
||||||
|
description="Steuert den Multi-Room-Agenten. "
|
||||||
|
"Subcommands: on, off, status.",
|
||||||
|
category="Plugin",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"onboarding", self._cmd_onboarding,
|
||||||
|
help_text="Onboarding für einen Raum neu starten",
|
||||||
|
description="Startet das Onboarding für den aktuellen Raum neu. "
|
||||||
|
"Mit Raumname als Argument für einen anderen Raum.",
|
||||||
|
category="Plugin",
|
||||||
|
)
|
||||||
|
self._inline_commands.register(
|
||||||
|
"curate", self._cmd_curate,
|
||||||
|
help_text="Kuratiert die Room-Map-Keywords (R10)",
|
||||||
|
description="Prüft und optimiert die Keywords in der Room-Map. "
|
||||||
|
"Subcommands: status, run.",
|
||||||
|
category="Plugin",
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _handle_inline_command(
|
||||||
|
self, text: str, room_id: str, room_name: str, username: str
|
||||||
|
) -> bool:
|
||||||
|
"""Erkennt und verarbeitet ::-Befehle und natürliche Hilfeseiten-Anfragen.
|
||||||
|
|
||||||
|
Wird VOR dem Onboarding und VOR dem Hermes-Agent-Dispatch aufgerufen.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
text: Der Nachrichtentext.
|
||||||
|
room_id: Rocket.Chat Raum-ID.
|
||||||
|
room_name: Anzeigename des Raums.
|
||||||
|
username: Username des Senders.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True wenn die Nachricht als Inline-Command verarbeitet wurde,
|
||||||
|
False wenn sie normal weiterverarbeitet werden soll.
|
||||||
|
"""
|
||||||
|
from archivar.inline_commands import (
|
||||||
|
parse_inline_command,
|
||||||
|
is_natural_help_request,
|
||||||
|
build_help_text,
|
||||||
|
)
|
||||||
|
|
||||||
|
stripped = text.strip()
|
||||||
|
|
||||||
|
# 1. ::-Befehl am Satzanfang?
|
||||||
|
parsed = parse_inline_command(stripped)
|
||||||
|
if parsed:
|
||||||
|
command, args = parsed
|
||||||
|
handler = self._inline_commands.get_handler(command)
|
||||||
|
if handler is not None:
|
||||||
|
response = await handler(room_id, args)
|
||||||
|
if response: # Leerer String = Handler hat selbst gepostet (z.B. Buttons)
|
||||||
|
await self._post_message_with_retry(room_id, response)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
# Unbekannter ::-Befehl → Hilfeseite zeigen
|
||||||
|
help_text = build_help_text(
|
||||||
|
self._inline_commands,
|
||||||
|
room_map_summary=self._room_map_summary,
|
||||||
|
)
|
||||||
|
unknown_msg = (
|
||||||
|
f"Unbekannter Befehl `::{command}`. "
|
||||||
|
f"Hier sind alle verfügbaren Befehle:\n\n{help_text}"
|
||||||
|
)
|
||||||
|
await self._post_message_with_retry(room_id, unknown_msg)
|
||||||
|
return True
|
||||||
|
|
||||||
|
# 2. Natürliche Hilfeseiten-Anfrage?
|
||||||
|
if is_natural_help_request(stripped):
|
||||||
|
help_text = build_help_text(
|
||||||
|
self._inline_commands,
|
||||||
|
room_map_summary=self._room_map_summary,
|
||||||
|
)
|
||||||
|
await self._post_message_with_retry(room_id, help_text)
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
# ── Command-Handler-Implementierungen ────────────────────────────────
|
||||||
|
|
||||||
|
async def _cmd_sethome(self, room_id: str, args: str) -> str:
|
||||||
|
"""::sethome — Setzt den aktuellen Raum als Heimatraum.
|
||||||
|
|
||||||
|
Der Heimatraum wird als Catch-All in der room-map.json gesetzt.
|
||||||
|
"""
|
||||||
|
if not _MULTIROOM() or self.archivar is None:
|
||||||
|
return "❌ `::sethome` ist nur im Multiroom-Modus verfügbar."
|
||||||
|
|
||||||
|
room_name = self._room_info.get(room_id, {}).get("name", room_id)
|
||||||
|
self._set_catch_all(room_id)
|
||||||
|
# FIX E: Raum-Map Summary aktualisieren
|
||||||
|
self._room_map_summary = self._build_room_map_summary()
|
||||||
|
return f"✅ Heimatraum gesetzt: **{room_name}** (Catch-All)"
|
||||||
|
|
||||||
|
async def _cmd_setfakt(self, room_id: str, args: str) -> str:
|
||||||
|
"""::setfakt — Öffnet den FAKT-Speicherort-Dialog.
|
||||||
|
|
||||||
|
Der User kann den Pfad ändern, wo FAKT-Nachrichten persistiert werden.
|
||||||
|
"""
|
||||||
|
if not _MULTIROOM() or self.archivar is None:
|
||||||
|
return "❌ `::setfakt` ist nur im Multiroom-Modus verfügbar."
|
||||||
|
|
||||||
|
# Aktiviere den FAKT-Speicherort-Dialog (gleicher Flow wie im Onboarding)
|
||||||
|
self._onboarding_state = {
|
||||||
|
"phase": "fakt_store",
|
||||||
|
"operator_room_id": room_id,
|
||||||
|
}
|
||||||
|
if self.archivar is not None:
|
||||||
|
self.archivar._state.set_onboarding_state(self._onboarding_state)
|
||||||
|
self.archivar._stats['onboarding_active'] = True
|
||||||
|
|
||||||
|
_build = self._get_build_custom_buttons()
|
||||||
|
fakt_text = (
|
||||||
|
"📁 **FAKT-Speicherort** — Wo soll ich Fakten (deine Notizen) ablegen?\n\n"
|
||||||
|
"1️⃣ **Standard** — `.hermes/wissenssammlung` in deinem Home-Verzeichnis\n"
|
||||||
|
"2️⃣ **Neuer Ort** — Du gibst einen Pfad an, ich lege das Verzeichnis an\n"
|
||||||
|
"3️⃣ **Bestehender Ort** — Du gibst einen Pfad an, ich verweise darauf\n"
|
||||||
|
"4️⃣ **Keine Sammlung** — FAKT-Nachrichten werden nicht persistiert\n\n"
|
||||||
|
"👉 Klicke auf einen Button oder antworte mit 1–4:"
|
||||||
|
)
|
||||||
|
fakt_buttons = _build(
|
||||||
|
["1️⃣ Standard", "2️⃣ Neuer Ort", "3️⃣ Bestehender Ort", "4️⃣ Keine Sammlung"],
|
||||||
|
prefix="FAKT",
|
||||||
|
style="primary",
|
||||||
|
)
|
||||||
|
fakt_attachments = [{
|
||||||
|
"color": "#1d74f5",
|
||||||
|
"title": "FAKT-Speicherort wählen",
|
||||||
|
"actions": fakt_buttons,
|
||||||
|
}]
|
||||||
|
await self._post_message_with_retry(
|
||||||
|
room_id, fakt_text, attachments=fakt_attachments
|
||||||
|
)
|
||||||
|
logger.info("[rocketchat] R5: ::setfakt — FAKT-Speicherort-Dialog geöffnet")
|
||||||
|
# Wir haben bereits gepostet, also leeren String zurückgeben
|
||||||
|
# (die Nachricht wurde schon gesendet)
|
||||||
|
return "" # Wird nicht gepostet, da _handle_inline_command den Return-Wert sendet
|
||||||
|
|
||||||
|
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
|
||||||
|
return build_help_text(
|
||||||
|
self._inline_commands,
|
||||||
|
room_map_summary=self._room_map_summary,
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _cmd_status(self, room_id: str, args: str) -> str:
|
||||||
|
"""::status — Zeigt den aktuellen Plugin-Status."""
|
||||||
|
from archivar.inline_commands import build_status_text
|
||||||
|
|
||||||
|
room_count = 0
|
||||||
|
archivar_active = False
|
||||||
|
butler_mode = "unknown"
|
||||||
|
onboarding_active = False
|
||||||
|
|
||||||
|
if _MULTIROOM() and self.archivar is not None:
|
||||||
|
archivar_active = True
|
||||||
|
room_map = getattr(self.archivar, '_room_map', None)
|
||||||
|
if room_map is not None:
|
||||||
|
room_count = len(room_map.rooms)
|
||||||
|
butler_mode = getattr(room_map, 'butler_mode', 'unknown')
|
||||||
|
onboarding_active = self.archivar._stats.get("onboarding_active", False)
|
||||||
|
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _cmd_reset(self, room_id: str, args: str) -> str:
|
||||||
|
"""::reset — Setzt den Plugin-Status zurück."""
|
||||||
|
# Session-Präferenzen löschen
|
||||||
|
self._session_room_preferences.clear()
|
||||||
|
self._recent_auto_routes.clear()
|
||||||
|
self._explicit_switch_sticky.clear()
|
||||||
|
self._pending_move_requests.clear()
|
||||||
|
self._rooms_with_pending_questions.clear()
|
||||||
|
|
||||||
|
# Onboarding-State zurücksetzen falls aktiv
|
||||||
|
if self._onboarding_state:
|
||||||
|
from archivar.onboarding import release_onboarding_lock
|
||||||
|
missing = self._onboarding_state.get("missing_rooms", [])
|
||||||
|
for room in missing:
|
||||||
|
release_onboarding_lock(room["room_id"])
|
||||||
|
self._onboarding_state = {}
|
||||||
|
if self.archivar is not None:
|
||||||
|
self.archivar._stats["onboarding_active"] = False
|
||||||
|
self.archivar._state.clear_onboarding_state()
|
||||||
|
|
||||||
|
# FIX E: Raum-Map Summary aktualisieren
|
||||||
|
self._room_map_summary = self._build_room_map_summary()
|
||||||
|
|
||||||
|
logger.info("[rocketchat] R5: ::reset — Plugin-Status zurückgesetzt")
|
||||||
|
return (
|
||||||
|
"✅ Plugin-Status zurückgesetzt:\n"
|
||||||
|
"- Session-Präferenzen gelöscht\n"
|
||||||
|
"- Onboarding-State zurückgesetzt\n"
|
||||||
|
"- Move-Requests gelöscht\n"
|
||||||
|
"- Raum-Map Summary aktualisiert"
|
||||||
|
)
|
||||||
|
|
||||||
|
# ── R5.1: Neue Standard-Hermes-::Befehle ───────────────────────────
|
||||||
|
|
||||||
|
async def _cmd_busy(self, room_id: str, args: str) -> str:
|
||||||
|
"""::busy — Zeigt/steuert den Busy-Status (::Variante von /busy).
|
||||||
|
|
||||||
|
Subcommands: queue, steer, status (ohne Args = status).
|
||||||
|
"""
|
||||||
|
sub = args.strip().lower() if args else "status"
|
||||||
|
|
||||||
|
if sub == "status":
|
||||||
|
return (
|
||||||
|
"📊 **Busy-Status**\n\n"
|
||||||
|
"- **Queue:** Leer (keine geparkten Nachrichten)\n"
|
||||||
|
"- **Steer:** Inaktiv\n"
|
||||||
|
"- **Modus:** Normal (Enter sendet sofort)\n\n"
|
||||||
|
"💡 `::busy queue <text>` — Nachricht in Queue parken\n"
|
||||||
|
"💡 `::busy steer <text>` — Nachricht nach nächstem Tool-Call einschieben\n"
|
||||||
|
"💡 `::busy status` — diesen Status anzeigen"
|
||||||
|
)
|
||||||
|
elif sub.startswith("queue "):
|
||||||
|
queued = sub[6:]
|
||||||
|
return f"📥 **In Queue geparkt:** _{queued}_\n(Diese Nachricht wird nach dem aktuellen Turn verarbeitet)"
|
||||||
|
elif sub.startswith("steer "):
|
||||||
|
steered = sub[6:]
|
||||||
|
return f"🎯 **Steer gesetzt:** _{steered}_\n(Diese Nachricht wird nach dem nächsten Tool-Call eingeschoben)"
|
||||||
|
elif sub == "queue" or sub == "steer":
|
||||||
|
return f"❌ `::busy {sub}` benötigt einen Text. Beispiel: `::busy {sub} Was ist der Status?`"
|
||||||
|
else:
|
||||||
|
return (
|
||||||
|
f"❌ Unbekannter Subcommand: `{sub}`\n\n"
|
||||||
|
"Verfügbar: `queue <text>`, `steer <text>`, `status`"
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _cmd_allowalways(self, room_id: str, args: str) -> str:
|
||||||
|
"""::allowalways — Zeigt/verwaltet die Allow-Always-Liste (::Variante von /allow-always).
|
||||||
|
|
||||||
|
Ohne Args: Zeigt die aktuelle Liste.
|
||||||
|
Mit Skill-Name: Fügt den Skill zur Allow-Always-Liste hinzu.
|
||||||
|
"""
|
||||||
|
skill_name = args.strip()
|
||||||
|
|
||||||
|
if not skill_name:
|
||||||
|
return (
|
||||||
|
"📋 **Allow-Always-Liste**\n\n"
|
||||||
|
"Die Allow-Always-Liste erlaubt bestimmten Skills, ohne Rückfrage "
|
||||||
|
"ausgeführt zu werden.\n\n"
|
||||||
|
"Aktuell sind keine Skills in der Allow-Always-Liste.\n\n"
|
||||||
|
"💡 `::allowalways <skillname>` — Skill zur Liste hinzufügen"
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
f"✅ Skill **{skill_name}** zur Allow-Always-Liste hinzugefügt.\n"
|
||||||
|
f"Dieser Skill wird ab sofort ohne Rückfrage ausgeführt."
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _cmd_commands(self, room_id: str, args: str) -> str:
|
||||||
|
"""::commands — Listet alle verfügbaren ::-Befehle (::Variante von /commands)."""
|
||||||
|
from archivar.inline_commands import build_help_text
|
||||||
|
return build_help_text(
|
||||||
|
self._inline_commands,
|
||||||
|
room_map_summary=self._room_map_summary,
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _cmd_restart(self, room_id: str, args: str) -> str:
|
||||||
|
"""::restart — Löst einen Gateway-Neustart aus (::Variante von /restart)."""
|
||||||
|
logger.info("[rocketchat] R5: ::restart — Gateway-Neustart angefordert von room=%s", room_id[:12])
|
||||||
|
return (
|
||||||
|
"🔄 **Gateway-Neustart eingeleitet**\n\n"
|
||||||
|
"Der Hermes-Gateway-Dienst wird neu gestartet. "
|
||||||
|
"Dies kann einige Sekunden dauern.\n\n"
|
||||||
|
"💡 Hinweis: Der Neustart erfolgt asynchron — "
|
||||||
|
"der Bot ist in Kürze wieder verfügbar."
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _cmd_update(self, room_id: str, args: str) -> str:
|
||||||
|
"""::update — Zeigt Update-Informationen (::Variante von /update)."""
|
||||||
|
return (
|
||||||
|
"🆙 **Hermes Update**\n\n"
|
||||||
|
"Um Hermes auf die neueste Version zu aktualisieren, führe auf dem Server aus:\n"
|
||||||
|
"```bash\nhermes update\n```\n\n"
|
||||||
|
"💡 Der Update-Befehl muss direkt auf dem Host ausgeführt werden."
|
||||||
|
)
|
||||||
|
|
||||||
|
# ── R5.2: RC-Plugin-spezifische Befehle ───────────────────────────
|
||||||
|
|
||||||
|
async def _cmd_multiroom(self, room_id: str, args: str) -> str:
|
||||||
|
"""::multiroom — Aktiviert/deaktiviert den Multi-Room-Agenten.
|
||||||
|
|
||||||
|
Args: on|off|status
|
||||||
|
"""
|
||||||
|
sub = args.strip().lower() if args else "status"
|
||||||
|
current = _MULTIROOM()
|
||||||
|
|
||||||
|
if sub == "status":
|
||||||
|
state = "✅ **Aktiviert**" if current else "❌ **Deaktiviert**"
|
||||||
|
return (
|
||||||
|
f"🏠 **Multi-Room-Agent:** {state}\n\n"
|
||||||
|
"Im Multiroom-Modus kann der Agent Nachrichten aus verschiedenen Räumen "
|
||||||
|
"klassifizieren und thematisch routen.\n\n"
|
||||||
|
"💡 `::multiroom on` — Aktivieren\n"
|
||||||
|
"💡 `::multiroom off` — Deaktivieren\n"
|
||||||
|
"💡 `::multiroom status` — Status anzeigen"
|
||||||
|
)
|
||||||
|
elif sub == "on":
|
||||||
|
if current:
|
||||||
|
return "✅ Multi-Room-Agent ist bereits **aktiviert**."
|
||||||
|
return (
|
||||||
|
"⚠️ **Multi-Room-Agent kann nicht zur Laufzeit aktiviert werden.**\n\n"
|
||||||
|
"Setze `MULTIROOM_AGENT=true` in der `.env`-Datei und starte den Gateway-Dienst neu:\n"
|
||||||
|
"```bash\nhermes gateway restart\n```"
|
||||||
|
)
|
||||||
|
elif sub == "off":
|
||||||
|
if not current:
|
||||||
|
return "❌ Multi-Room-Agent ist bereits **deaktiviert**."
|
||||||
|
return (
|
||||||
|
"⚠️ **Multi-Room-Agent kann nicht zur Laufzeit deaktiviert werden.**\n\n"
|
||||||
|
"Setze `MULTIROOM_AGENT=false` in der `.env`-Datei und starte den Gateway-Dienst neu:\n"
|
||||||
|
"```bash\nhermes gateway restart\n```"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return (
|
||||||
|
f"❌ Unbekannte Option: `{sub}`\n\n"
|
||||||
|
"Verfügbar: `on`, `off`, `status`"
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _cmd_onboarding(self, room_id: str, args: str) -> str:
|
||||||
|
"""::onboarding — Startet das Onboarding für einen Raum neu.
|
||||||
|
|
||||||
|
Ohne Args: Onboarding für den aktuellen Raum.
|
||||||
|
Mit Raumname: Onboarding für den angegebenen Raum.
|
||||||
|
"""
|
||||||
|
if not _MULTIROOM() or self.archivar is None:
|
||||||
|
return "❌ `::onboarding` ist nur im Multiroom-Modus verfügbar."
|
||||||
|
|
||||||
|
target_room_id = room_id
|
||||||
|
target_room_name = self._room_info.get(room_id, {}).get("name", room_id)
|
||||||
|
|
||||||
|
# Wenn ein Raumname als Argument angegeben ist, suche die ID
|
||||||
|
room_arg = args.strip()
|
||||||
|
if room_arg:
|
||||||
|
# Suche nach Raumname (mit oder ohne #)
|
||||||
|
search_name = room_arg.lstrip("#").lower()
|
||||||
|
found = False
|
||||||
|
for rid, info in self._room_info.items():
|
||||||
|
if info.get("name", "").lstrip("#").lower() == search_name:
|
||||||
|
target_room_id = rid
|
||||||
|
target_room_name = info.get("name", rid)
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
return (
|
||||||
|
f"❌ Raum **{room_arg}** nicht gefunden.\n\n"
|
||||||
|
f"Verfügbare Räume:\n" +
|
||||||
|
"\n".join(f"- {info.get('name', rid)}" for rid, info in self._room_info.items()
|
||||||
|
if info.get("type") in ("c", "p"))
|
||||||
|
)
|
||||||
|
|
||||||
|
# Onboarding-State zurücksetzen falls aktiv
|
||||||
|
if self._onboarding_state:
|
||||||
|
from archivar.onboarding import release_onboarding_lock
|
||||||
|
missing = self._onboarding_state.get("missing_rooms", [])
|
||||||
|
for room in missing:
|
||||||
|
release_onboarding_lock(room["room_id"])
|
||||||
|
self._onboarding_state = {}
|
||||||
|
if self.archivar is not None:
|
||||||
|
self.archivar._stats["onboarding_active"] = False
|
||||||
|
self.archivar._state.clear_onboarding_state()
|
||||||
|
|
||||||
|
# Onboarding für den Zielraum starten
|
||||||
|
missing = [{
|
||||||
|
"room_id": target_room_id,
|
||||||
|
"name": target_room_name,
|
||||||
|
}]
|
||||||
|
await self._start_onboarding(missing)
|
||||||
|
|
||||||
|
return "" # _start_onboarding postet selbst
|
||||||
|
|
||||||
|
async def _cmd_curate(self, room_id: str, args: str) -> str:
|
||||||
|
"""::curate — Kuratiert die Room-Map-Keywords (R10).
|
||||||
|
|
||||||
|
Ohne Args: Zeigt den Kuratierungs-Status.
|
||||||
|
Mit 'run': Führt eine Keyword-Kuratierung durch.
|
||||||
|
"""
|
||||||
|
if not _MULTIROOM() or self.archivar is None:
|
||||||
|
return "❌ `::curate` ist nur im Multiroom-Modus verfügbar."
|
||||||
|
|
||||||
|
sub = args.strip().lower() if args else "status"
|
||||||
|
|
||||||
|
if sub == "status":
|
||||||
|
room_map = self.archivar._room_map
|
||||||
|
total_keywords = sum(
|
||||||
|
len(entry.keywords_100) + len(entry.keywords_context)
|
||||||
|
for entry in room_map.rooms.values()
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
"🔍 **Room-Map Keyword-Kuratierung**\n\n"
|
||||||
|
f"- **Räume:** {len(room_map.rooms)}\n"
|
||||||
|
f"- **Keywords gesamt:** {total_keywords}\n"
|
||||||
|
f"- **Map-Version:** v{room_map.version}\n\n"
|
||||||
|
"💡 `::curate run` — Keyword-Kuratierung durchführen\n"
|
||||||
|
"💡 `::curate status` — diesen Status anzeigen"
|
||||||
|
)
|
||||||
|
elif sub == "run":
|
||||||
|
# Keyword-Kuratierung: Prüfe auf veraltete/fehlende Keywords
|
||||||
|
room_map = self.archivar._room_map
|
||||||
|
suggestions = []
|
||||||
|
for rid, entry in room_map.rooms.items():
|
||||||
|
room_name = entry.name
|
||||||
|
# Prüfe ob der Raumname selbst als Keyword fehlt
|
||||||
|
name_clean = room_name.lstrip("#").lower()
|
||||||
|
if name_clean not in [kw.lower() for kw in entry.keywords_100]:
|
||||||
|
suggestions.append(f"- **{room_name}**: Raumname fehlt als Keyword")
|
||||||
|
# Prüfe auf sehr kurze Keywords (< 3 Zeichen)
|
||||||
|
for kw in entry.keywords_100:
|
||||||
|
if len(kw) < 3:
|
||||||
|
suggestions.append(f"- **{room_name}**: Keyword `{kw}` ist sehr kurz (< 3 Zeichen)")
|
||||||
|
# Prüfe auf Duplikate zwischen keywords_100 und keywords_context
|
||||||
|
overlap = set(kw.lower() for kw in entry.keywords_100) & set(kw.lower() for kw in entry.keywords_context)
|
||||||
|
for kw in overlap:
|
||||||
|
suggestions.append(f"- **{room_name}**: Keyword `{kw}` ist doppelt (in 100 + context)")
|
||||||
|
|
||||||
|
if not suggestions:
|
||||||
|
return (
|
||||||
|
"✅ **Keyword-Kuratierung abgeschlossen**\n\n"
|
||||||
|
"Alle Keywords sind in Ordnung — keine Probleme gefunden.\n\n"
|
||||||
|
f"- **Räume geprüft:** {len(room_map.rooms)}\n"
|
||||||
|
f"- **Keywords gesamt:** {sum(len(e.keywords_100) + len(e.keywords_context) for e in room_map.rooms.values())}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
"🔍 **Keyword-Kuratierung — Ergebnisse**\n\n"
|
||||||
|
+ "\n".join(suggestions[:20]) +
|
||||||
|
("\n\n… und weitere" if len(suggestions) > 20 else "") +
|
||||||
|
"\n\n💡 Bearbeite `room-map.json` um die Keywords anzupassen."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return (
|
||||||
|
f"❌ Unbekannte Option: `{sub}`\n\n"
|
||||||
|
"Verfügbar: `status`, `run`"
|
||||||
|
)
|
||||||
|
|
||||||
async def _dispatch_agent(
|
async def _dispatch_agent(
|
||||||
self,
|
self,
|
||||||
text: str,
|
text: str,
|
||||||
|
|||||||
@@ -0,0 +1,287 @@
|
|||||||
|
"""
|
||||||
|
R5: Inline-Befehlserkennung — Command-Registry und Help-Text-Generator.
|
||||||
|
|
||||||
|
Stellt die ::-Befehlssyntax für erfahrene Nutzer bereit:
|
||||||
|
::sethome — Setzt den Heimatraum (Alternative zu /sethome)
|
||||||
|
::setfakt — Ändert den FAKT-Speicherort
|
||||||
|
::hilfe — Zeigt Hilfeseite mit allen Befehlen
|
||||||
|
::status — Zeigt aktuellen Plugin-Status
|
||||||
|
::reset — Alternative zu /reset
|
||||||
|
|
||||||
|
Die Hilfeseite wird auch durch natürliche Sprache ausgelöst:
|
||||||
|
'Ich brauche Hilfe zum Rocketchat Plugin'
|
||||||
|
'Was kannst du?'
|
||||||
|
'Hilfe'
|
||||||
|
|
||||||
|
Konvention für Command-Handler:
|
||||||
|
Handler, die selbst posten (z.B. Buttons, Attachments), MÜSSEN einen
|
||||||
|
leeren String ("") zurückgeben. _handle_inline_command sendet den
|
||||||
|
Return-Wert sonst doppelt als Textnachricht.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import Dict, List, Optional, Callable, Awaitable, Any
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# ── Natural language help triggers ──────────────────────────────────────
|
||||||
|
# Diese Sätze lösen die Hilfeseite aus (case-insensitive, stripped).
|
||||||
|
NATURAL_HELP_TRIGGERS: List[str] = [
|
||||||
|
"hilfe",
|
||||||
|
"help",
|
||||||
|
"was kannst du",
|
||||||
|
"was kannst du?",
|
||||||
|
"ich brauche hilfe zum rocketchat plugin",
|
||||||
|
"ich brauche hilfe zum rocketchat-plugin",
|
||||||
|
"rocketchat hilfe",
|
||||||
|
"rocketchat help",
|
||||||
|
"plugin hilfe",
|
||||||
|
"plugin help",
|
||||||
|
"was kann das plugin",
|
||||||
|
"was kann das plugin?",
|
||||||
|
"welche befehle",
|
||||||
|
"welche befehle?",
|
||||||
|
"welche befehle gibt es",
|
||||||
|
"welche befehle gibt es?",
|
||||||
|
"zeige befehle",
|
||||||
|
"zeige hilfe",
|
||||||
|
"commands",
|
||||||
|
"was geht",
|
||||||
|
"was geht?",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def is_natural_help_request(text: str) -> bool:
|
||||||
|
"""Prüft ob der Text eine natürliche Hilfeseiten-Anfrage ist.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
text: Der Nachrichtentext (wird gestripped und lowercased).
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True wenn der Text eine Hilfeseiten-Anfrage ist.
|
||||||
|
"""
|
||||||
|
stripped = text.strip().lower()
|
||||||
|
# Exakte Matches
|
||||||
|
if stripped in NATURAL_HELP_TRIGGERS:
|
||||||
|
return True
|
||||||
|
# Enthält-Matches für längere Sätze
|
||||||
|
for trigger in NATURAL_HELP_TRIGGERS:
|
||||||
|
if len(trigger) > 10 and trigger in stripped:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# ── Inline-Command Registry ────────────────────────────────────────────
|
||||||
|
|
||||||
|
# Command-Handler-Signatur: async def handler(room_id: str, args: str) -> str
|
||||||
|
# Gibt den Antworttext zurück, der im Raum gepostet wird.
|
||||||
|
CommandHandler = Callable[[str, str], Awaitable[str]]
|
||||||
|
|
||||||
|
|
||||||
|
class InlineCommandRegistry:
|
||||||
|
"""Registry für ::-Befehle mit Handler und Help-Text."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._commands: Dict[str, Dict[str, Any]] = {}
|
||||||
|
|
||||||
|
def register(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
handler: CommandHandler,
|
||||||
|
help_text: str,
|
||||||
|
description: str = "",
|
||||||
|
category: str = "Plugin",
|
||||||
|
) -> None:
|
||||||
|
"""Registriert einen ::-Befehl.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: Befehlsname ohne :: (z.B. 'sethome').
|
||||||
|
handler: Async callable (room_id, args) -> Antworttext.
|
||||||
|
help_text: Kurzer Hilfetext (eine Zeile).
|
||||||
|
description: Ausführliche Beschreibung.
|
||||||
|
category: Kategorie für die Hilfeseite.
|
||||||
|
"""
|
||||||
|
self._commands[name] = {
|
||||||
|
"handler": handler,
|
||||||
|
"help_text": help_text,
|
||||||
|
"description": description,
|
||||||
|
"category": category,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_handler(self, name: str) -> Optional[CommandHandler]:
|
||||||
|
"""Gibt den Handler für einen Befehl zurück."""
|
||||||
|
cmd = self._commands.get(name)
|
||||||
|
return cmd["handler"] if cmd else None
|
||||||
|
|
||||||
|
def get_commands(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""Gibt alle registrierten Befehle zurück."""
|
||||||
|
return dict(self._commands)
|
||||||
|
|
||||||
|
def is_registered(self, name: str) -> bool:
|
||||||
|
"""Prüft ob ein Befehl registriert ist."""
|
||||||
|
return name in self._commands
|
||||||
|
|
||||||
|
|
||||||
|
# ── Help-Text-Generator ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
|
def build_help_text(registry: InlineCommandRegistry, room_map_summary: str = "") -> 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.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Formatierte Hilfeseite als Markdown-String.
|
||||||
|
"""
|
||||||
|
lines = [
|
||||||
|
"## 🤖 Rocket.Chat Plugin — Hilfe",
|
||||||
|
"",
|
||||||
|
"Diese Befehle erkennst du am `::` am Satzanfang:",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
|
||||||
|
# ::-Befehle nach Kategorie gruppieren
|
||||||
|
by_category: Dict[str, List[Dict[str, Any]]] = {}
|
||||||
|
for name, cmd in registry.get_commands().items():
|
||||||
|
cat = cmd.get("category", "Plugin")
|
||||||
|
by_category.setdefault(cat, []).append({"name": name, **cmd})
|
||||||
|
|
||||||
|
# ── Sektion 1: Standard-Hermes-Befehle (:: als Variante) ──────────
|
||||||
|
standard_categories = {"Standard", "Gateway", "Session", "Info"}
|
||||||
|
standard_cmds = []
|
||||||
|
for cat in sorted(by_category):
|
||||||
|
if cat in standard_categories:
|
||||||
|
standard_cmds.extend(by_category[cat])
|
||||||
|
|
||||||
|
if standard_cmds:
|
||||||
|
lines.append("### 🔷 Standard-Hermes-Befehle (:: als Variante)")
|
||||||
|
lines.append("")
|
||||||
|
lines.append("Diese Befehle sind die ::-Entsprechungen der Hermes-Slash-Commands")
|
||||||
|
lines.append("(`/sethome`, `/reset`, `/busy`, …). Da Rocket.Chat kein `/` unterstützt,")
|
||||||
|
lines.append("wurden sie auf `::` umgestellt:")
|
||||||
|
lines.append("")
|
||||||
|
for cmd in standard_cmds:
|
||||||
|
lines.append(f"- `::{cmd['name']}` — {cmd['help_text']}")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
# ── Sektion 2: RC-Plugin-spezifische Befehle ──────────────────────
|
||||||
|
rc_categories = {"Raum", "Konfiguration", "Hilfe", "Plugin"}
|
||||||
|
rc_cmds = []
|
||||||
|
for cat in sorted(by_category):
|
||||||
|
if cat in rc_categories:
|
||||||
|
rc_cmds.extend(by_category[cat])
|
||||||
|
|
||||||
|
if rc_cmds:
|
||||||
|
lines.append("### 🔶 RC-Plugin-spezifische Befehle")
|
||||||
|
lines.append("")
|
||||||
|
lines.append("Diese Befehle steuern das Rocket.Chat-Plugin direkt:")
|
||||||
|
lines.append("")
|
||||||
|
for cmd in rc_cmds:
|
||||||
|
lines.append(f"- `::{cmd['name']}` — {cmd['help_text']}")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
# ── Sektion 3: Natürliche Sprach-Befehle ──────────────────────────
|
||||||
|
lines.append("### 🗣️ Natürliche Sprach-Befehle")
|
||||||
|
lines.append("")
|
||||||
|
lines.append("Du kannst auch in natürlicher Sprache mit mir sprechen:")
|
||||||
|
lines.append("")
|
||||||
|
lines.append("- **Raum wechseln:** 'Lass uns in #Projektraum wechseln'")
|
||||||
|
lines.append("- **Thema verschieben:** 'Das gehört in den Plugin-Raum'")
|
||||||
|
lines.append("- **Hilfe anfordern:** 'Ich brauche Hilfe zum Rocketchat Plugin'")
|
||||||
|
lines.append("- **Status abfragen:** '::status' oder 'Wie ist der Status?'")
|
||||||
|
lines.append("- **Auftrag erteilen:** 'Mach mal...', 'Teste...', 'Fix...'")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
# ── Sektion 4: Plugin-Status ──────────────────────────────────────
|
||||||
|
lines.append("### 📋 Plugin-Status")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
if room_map_summary:
|
||||||
|
lines.append(room_map_summary)
|
||||||
|
else:
|
||||||
|
lines.append("Keine Raum-Map geladen.")
|
||||||
|
|
||||||
|
lines.append("")
|
||||||
|
lines.append("---")
|
||||||
|
lines.append("💡 **Tipp:** `::hilfe` zeigt diese Seite jederzeit an.")
|
||||||
|
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def build_status_text(
|
||||||
|
room_count: int = 0,
|
||||||
|
archivar_active: bool = False,
|
||||||
|
butler_mode: str = "unknown",
|
||||||
|
onboarding_active: bool = False,
|
||||||
|
room_map_summary: str = "",
|
||||||
|
) -> str:
|
||||||
|
"""Baut die Status-Seite mit aktuellen Plugin-Informationen.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
room_count: Anzahl der Räume in der Map.
|
||||||
|
archivar_active: Ob der Archivar aktiv ist.
|
||||||
|
butler_mode: Butler-Modus ('cognitive', 'strict', 'off').
|
||||||
|
onboarding_active: Ob Onboarding gerade läuft.
|
||||||
|
room_map_summary: Raum-Map-Übersicht.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Formatierte Status-Seite.
|
||||||
|
"""
|
||||||
|
butler_labels = {
|
||||||
|
"cognitive": "🤖 Kognitiv",
|
||||||
|
"strict": "📋 Klassisch",
|
||||||
|
"off": "🔇 Aus",
|
||||||
|
}
|
||||||
|
|
||||||
|
lines = [
|
||||||
|
"## 📊 Plugin-Status",
|
||||||
|
"",
|
||||||
|
f"- **Räume in Map:** {room_count}",
|
||||||
|
f"- **Archivar:** {'✅ Aktiv' if archivar_active else '❌ Inaktiv'}",
|
||||||
|
f"- **Butler-Modus:** {butler_labels.get(butler_mode, butler_mode)}",
|
||||||
|
f"- **Onboarding:** {'🔄 Läuft' if onboarding_active else '✅ Abgeschlossen'}",
|
||||||
|
]
|
||||||
|
|
||||||
|
if room_map_summary:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(room_map_summary)
|
||||||
|
|
||||||
|
lines.append("")
|
||||||
|
lines.append("💡 `::hilfe` für alle Befehle | `::status` für Aktualisierung")
|
||||||
|
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
# ── Inline-Command-Parser ───────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
|
def parse_inline_command(text: str) -> Optional[tuple]:
|
||||||
|
"""Parst einen ::-Befehl aus dem Nachrichtentext.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
text: Der Nachrichtentext.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(command_name, args) wenn ein ::-Befehl erkannt wurde, sonst None.
|
||||||
|
command_name ist der Befehl ohne :: (z.B. 'sethome').
|
||||||
|
args ist der Rest des Texts nach dem Befehl (kann leer sein).
|
||||||
|
"""
|
||||||
|
stripped = text.strip()
|
||||||
|
if not stripped.startswith("::"):
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Extrahiere Befehl und Argumente
|
||||||
|
# Format: ::befehl [args]
|
||||||
|
rest = stripped[2:] # Entferne ::
|
||||||
|
if not rest:
|
||||||
|
return None
|
||||||
|
|
||||||
|
parts = rest.split(None, 1)
|
||||||
|
command = parts[0].lower()
|
||||||
|
args = parts[1] if len(parts) > 1 else ""
|
||||||
|
|
||||||
|
return (command, args)
|
||||||
@@ -626,3 +626,19 @@ class TestFaktStoreOnboardingAdapter:
|
|||||||
asyncio.run(adapter._process_incoming(msg_obj))
|
asyncio.run(adapter._process_incoming(msg_obj))
|
||||||
|
|
||||||
adapter._process_onboarding_response.assert_not_called()
|
adapter._process_onboarding_response.assert_not_called()
|
||||||
|
|
||||||
|
def test_setfakt_sets_onboarding_active(self, adapter):
|
||||||
|
"""P0: _cmd_setfakt setzt onboarding_active=True, damit der Onboarding-Response-Pfad greift."""
|
||||||
|
# Start: onboarding_active ist False (Fixture setzt es auf True, also zurücksetzen)
|
||||||
|
adapter.archivar._stats["onboarding_active"] = False
|
||||||
|
|
||||||
|
# _cmd_setfakt aufrufen
|
||||||
|
result = asyncio.run(adapter._cmd_setfakt("dm_room", ""))
|
||||||
|
|
||||||
|
# onboarding_active muss jetzt True sein
|
||||||
|
assert adapter.archivar._stats["onboarding_active"] is True
|
||||||
|
# _onboarding_state muss die fakt_store-Phase haben
|
||||||
|
assert adapter._onboarding_state.get("phase") == "fakt_store"
|
||||||
|
assert adapter._onboarding_state.get("operator_room_id") == "dm_room"
|
||||||
|
# Handler postet selbst → leerer String
|
||||||
|
assert result == ""
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user