feat(archivar): auto-onboarding — room-map completeness check after gateway start
Implements the RC-Skill's promised room-map completeness check after Adapter.connect(). Previously the adapter subscribed to rooms but never verified they were all present in room-map.json. New rooms were subscribed but invisible to the Archivar router. Scope (~450 lines, 4 files): - adapter_integration.py: check_room_map_completeness() compares subscribed rooms (filtered to c/p types) against RoomMap. Single-Room-Regel: 1 relevant room → auto catch_all, no interview. onboarding_active flag in _stats prevents re-triggering. - room_map.py: add_or_update_room() for safe in-memory mutations, reload() for disk-to-memory sync without gateway restart, static save() for atomic file writes. - adapter.py: connect() calls check after Archivar init, triggers _start_onboarding() if rooms missing. _process_incoming() intercepts 'Raum: #Name = Thema' responses during active onboarding. - test_auto_onboarding.py: 4 unit tests covering single-room auto-assign, multi-room detection, DM filtering, and already- complete map (no action). Deployed to production: adapter.py + archivar/*.py copied to Auslieferungspfad. Gateway restarted — no onboarding triggered (map already complete).
This commit is contained in:
@@ -260,6 +260,100 @@ class RoomMap:
|
||||
|
||||
return cls._from_dict(data)
|
||||
|
||||
def add_or_update_room(self, room_id: str, name: str, theme: str = "", keywords: Optional[list] = None, catch_all: bool = False) -> None:
|
||||
"""Fügt Raum zur In-Memory-Map hinzu ODER aktualisiert bestehenden.
|
||||
|
||||
Args:
|
||||
room_id: Rocket.Chat Raum-ID
|
||||
name: Menschenlesbarer Name (z.B. "#Rocketchat-Plugin")
|
||||
theme: Thema des Raums (ein Satz)
|
||||
keywords: Stichworte für Keyword-Matching
|
||||
catch_all: True wenn dieser Raum der EINE Catch-All-Raum ist
|
||||
"""
|
||||
if keywords is None:
|
||||
keywords = []
|
||||
|
||||
# Erstelle oder aktualisiere den RoomEntry
|
||||
self._rooms[room_id] = RoomEntry(
|
||||
room_id=room_id,
|
||||
name=name,
|
||||
theme=theme,
|
||||
keywords=keywords,
|
||||
catch_all=catch_all
|
||||
)
|
||||
|
||||
# Wenn dies ein Catch-All-Raum ist, stellen wir sicher, dass es nur einen gibt
|
||||
if catch_all:
|
||||
for rid, room in self._rooms.items():
|
||||
if rid != room_id and room.catch_all:
|
||||
# Entferne catch_all von anderen Räumen
|
||||
room.catch_all = False
|
||||
|
||||
def reload(self, path: Optional[Path] = None) -> None:
|
||||
"""Lädt room-map.json neu von Disk.
|
||||
|
||||
Aktualisiert die In-Memory-Repräsentation.
|
||||
Kein Gateway-Neustart nötig.
|
||||
|
||||
Args:
|
||||
path: Pfad zur JSON-Datei. Standardwert aus Umgebungsvariablen oder DEFAULT_MAP_PATH.
|
||||
"""
|
||||
if path is None:
|
||||
env_path = os.getenv("ARCHIVAR_ROOM_MAP_PATH", "").strip()
|
||||
if env_path:
|
||||
path = Path(env_path)
|
||||
else:
|
||||
path = Path(os.path.expanduser(DEFAULT_MAP_PATH))
|
||||
|
||||
if path.exists():
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Parse die neue Daten und aktualisiere die Instanz
|
||||
new_map = self._from_dict(data)
|
||||
self._rooms = new_map._rooms
|
||||
self._excluded_room_ids = new_map._excluded_room_ids
|
||||
self._fact_store_path = new_map._fact_store_path
|
||||
self._version = new_map._version
|
||||
|
||||
@staticmethod
|
||||
def save(room_map: 'RoomMap', path: Optional[Path] = None) -> None:
|
||||
"""Speichert die RoomMap in eine JSON-Datei.
|
||||
|
||||
Args:
|
||||
room_map: Die zu speichernde RoomMap-Instanz
|
||||
path: Pfad zur JSON-Datei. Standardwert aus Umgebungsvariablen oder DEFAULT_MAP_PATH.
|
||||
"""
|
||||
if path is None:
|
||||
env_path = os.getenv("ARCHIVAR_ROOM_MAP_PATH", "").strip()
|
||||
if env_path:
|
||||
path = Path(env_path)
|
||||
else:
|
||||
path = Path(os.path.expanduser(DEFAULT_MAP_PATH))
|
||||
|
||||
# Erstelle das Verzeichnis falls es nicht existiert
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Konvertiere die Map in ein serialisierbares Dict
|
||||
data = {
|
||||
"version": room_map._version,
|
||||
"rooms": {},
|
||||
"excluded_rooms": list(room_map._excluded_room_ids),
|
||||
"fact_store_path": str(room_map._fact_store_path)
|
||||
}
|
||||
|
||||
for room_id, room_entry in room_map._rooms.items():
|
||||
data["rooms"][room_id] = {
|
||||
"name": room_entry.name,
|
||||
"theme": room_entry.theme,
|
||||
"keywords": room_entry.keywords,
|
||||
"catch_all": room_entry.catch_all
|
||||
}
|
||||
|
||||
# Schreibe die Datei
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2, ensure_ascii=False)
|
||||
|
||||
@classmethod
|
||||
def _from_dict(cls, data: dict) -> RoomMap:
|
||||
"""Parse a deserialized map dict into a ``RoomMap`` instance."""
|
||||
|
||||
Reference in New Issue
Block a user