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:
Hermes Agent
2026-06-06 19:31:46 +02:00
parent 63e0616d7a
commit 8591933d8d
4 changed files with 450 additions and 0 deletions
+51
View File
@@ -38,7 +38,9 @@ from __future__ import annotations
import asyncio
import logging
import os
import time
from pathlib import Path
from typing import Any, Awaitable, Callable, Dict, Optional
from .classifier import (
@@ -134,6 +136,7 @@ class ArchivarMessageHandler:
"avg_latency_ms": 0.0, # float — gleitender Durchschnitt
"last_error": None, # str | None — letzter Fehler
"latencies": [], # list[float] — per-request ms
"onboarding_active": False, # Auto-Onboarding state
}
# ── RoomMap Loading ─────────────────────────────────────────────────
@@ -411,8 +414,56 @@ class ArchivarMessageHandler:
"avg_latency_ms": 0.0,
"last_error": None,
"latencies": [],
"onboarding_active": False,
}
def check_room_map_completeness(self, subscribed_rooms: dict) -> list[dict]:
"""Vergleicht subscribed rooms mit room-map.json.
Args:
subscribed_rooms: Mapping von room_id → {"name": str, "type": str} (vom Adapter)
Returns:
Liste fehlender Räume: [{"room_id": "...", "name": "#Raum"}]
Leere Liste = Map vollständig.
"""
# Filter: Nur Räume mit type in ("c", "p") berücksichtigen
relevant_rooms = {
rid: info for rid, info in subscribed_rooms.items()
if info.get("type") in ("c", "p")
}
# Single-Room-Regel: Wenn nur 1 relevanter Raum existiert und dieser
# nicht in der Map ist → automatisch als catch_all eintragen
if len(relevant_rooms) == 1:
single_room_id = list(relevant_rooms.keys())[0]
if single_room_id not in self._room_map.rooms:
# Automatisch als catch_all eintragen
room_info = relevant_rooms[single_room_id]
self._room_map.add_or_update_room(
room_id=single_room_id,
name=room_info["name"],
theme="Automatisch zugewiesener Catch-All-Raum",
keywords=[],
catch_all=True
)
# Speichern und neu laden
RoomMap.save(self._room_map, Path(ROOM_MAP_PATH))
self._room_map.reload()
logger.info("Single room detected — auto-assigned as catch_all: %s", room_info["name"])
return [] # Keine weiteren Maßnahmen nötig
# Normale Prüfung: Welche relevanten Räume fehlen in der Map?
missing = []
for room_id, room_info in relevant_rooms.items():
if room_id not in self._room_map.rooms:
missing.append({
"room_id": room_id,
"name": room_info["name"]
})
return missing
# ── Configuration ───────────────────────────────────────────────────
@property