From 4d356691742c93b21a22fa51f44263ec107db264 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sat, 6 Jun 2026 18:53:11 +0200 Subject: [PATCH] fix: prevent room-map.json overwrite + is_unrouteable handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ROOT CAUSE: install.sh --update-only blindly deployed room-map.json from the repo (containing 'GENERAL' as catch_all) to the production /home/bernd/.hermes/data/ directory, overwriting the machine-specific map. FIXES (3 changes): 1. REMOVED room-map.json from repo + added to .gitignore This file is machine-specific data, not source code. 2. REMOVED room-map.json deploy from install.sh (both paths): - Normal install block (section 3.5) - --update-only emergency deploy (section 3.5) Replaced with comment: 'MACHINE-SPECIFIC — created by RC-Skill onboarding' 3. FIX adapter.py: is_unrouteable guard on ContextVar routing Before: ContextVar set to target_room even when unrouteable Result: 'Ich antworte im Zielraum.' note appeared, but Hermes couldn't deliver to unsubscribed room — answer lost silently. After: Forward block checks not getattr(decision, 'is_unrouteable', False) If unrouteable → stays in origin room, answers there normally. PRODUCTION: Correct room-map.json deployed with 4 project rooms + DM catch_all on .101. Excluded rooms: multi-agent DM, testbot DM. --- .gitignore | 3 + ...026-06-06_060000-archivar-v2-raumrouter.md | 432 ++++++++++++++++++ install.sh | 32 +- plugin/adapter.py | 13 +- room-map.json | 12 - 5 files changed, 451 insertions(+), 41 deletions(-) create mode 100644 .gitignore create mode 100644 .hermes/plans/2026-06-06_060000-archivar-v2-raumrouter.md delete mode 100644 room-map.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2eb5c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +# room-map.json is machine-specific — never commit it +room-map.json diff --git a/.hermes/plans/2026-06-06_060000-archivar-v2-raumrouter.md b/.hermes/plans/2026-06-06_060000-archivar-v2-raumrouter.md new file mode 100644 index 0000000..73e4ce3 --- /dev/null +++ b/.hermes/plans/2026-06-06_060000-archivar-v2-raumrouter.md @@ -0,0 +1,432 @@ +# Archivar v2: Vollständiger Raum-Router — Implementation Plan + +> **For Hermes:** Use subagent-driven-development skill to implement this plan task-by-task. + +**Goal:** Den Archivar vom hybriden Kategorie-Klassifikator zum vollständigen thematischen Raum-Router umbauen. Embeddings und LLM fragen nicht mehr „FAKT/FRAGE/ALARM?", sondern „In welchen Raum gehört diese Nachricht thematisch?" + +**Architecture:** Der `MessageClassifier` wird von Kategorie-basierten Embeddings (FAKT/FRAGE/ALARM) auf Raum-basierte Embedding-Referenzen umgestellt. Der `LLM_CLASSIFY_PROMPT` wird durch `LLM_ROOM_PROMPT` auch in der Classifier-Stufe ersetzt. `adapter.py`-Logtext wird aktualisiert. Der Router-Flow (`router.py`) bleibt unverändert — er ist bereits korrekt. + +**Tech Stack:** Python 3.13, `nomic-embed-text` (768-dim), `qwen2.5:7b` (LLM), RoomMap-Datenmodell + +**Analyse-Quellen:** +- Commit `58f00c0` („Phase 1-3 — RoomMap + thematischer Router") +- Deployter Code unter `~/.hermes/hermes-agent/plugins/platforms/rocketchat/archivar/` +- `room-map.json` unter `~/.hermes/hermes-agent/data/room-map.json` + +--- + +## Befunde (Stand 06.06.2026) + +| # | Fund | Datei:Zeile | Schwere | +|---|---|---|---| +| F1 | `_initialize_sync()` vektorisiert `CATEGORY_TEXTS` (FAKT/FRAGE/ALARM) statt Raum-Kontext | `classifier.py:401-432` | Mittel | +| F2 | `_llm_classify_sync()` verwendet `LLM_CLASSIFY_PROMPT` statt `LLM_ROOM_PROMPT` | `classifier.py:350-361` | Mittel | +| F3 | Gateway-Logtext sagt „Embedding-basierte Nachrichten-Klassifikation" — sollte „Thematischer Raum-Router" sagen | `adapter.py:475` | Gering | +| F4 | `router.py`-Flow ist korrekt: Keyword→Embedding→LLM-Room→Catch-All | `router.py:152-296` | ✅ Keine Änderung | + +--- + +## Architekturentscheidung: Nicht die Embeddings umbauen — den Flow begradigen + +**Analyse:** Die Category-Embeddings (FAKT/FRAGE/ALARM) auf Raum-Embeddings umzustellen würde bedeuten, für jeden Raum einen Referenztext zu vektorisieren (9 Räume × 768-dim). Das ist teuer, erhöht die Latenz (9 Kosinus-Vergleiche statt 3) und die Raum-Texte (`RoomEntry.theme`) sind zu kurz für sinnvolle Embeddings. + +**Bessere Lösung:** Der Classifier bleibt als **Intent-Detector** (FAKT/FRAGE/ALARM), aber der Router übersetzt das Ergebnis **thematisch**: +- **Schritt 1 (neu):** Keyword-Match aus RoomMap (existiert bereits ✅) +- **Schritt 2:** Embedding-Klassifikation → Kategorie (FAKT/FRAGE/ALARM) +- **Schritt 3 (zu reparieren):** LLM-Klassifikation → `LLM_ROOM_PROMPT` statt `LLM_CLASSIFY_PROMPT` +- **Schritt 4:** FAKT → doc_store, FRAGE → LLM-Room-Lookup, ALARM → Catch-All + +**Nicht verändern:** +- `CATEGORY_TEXTS` bleiben (Intent-Detection ist nützlich) +- `_initialize_sync()` bleibt (vektorisiert 3 Kategorien, nicht 9 Räume) +- `router.py` bleibt (ist bereits korrekt) + +**Nur dies ändern:** +1. `classifier.py:355`: `LLM_CLASSIFY_PROMPT` → `LLM_ROOM_PROMPT` + Raum-Liste aus RoomMap +2. `classifier.py:346-361`: `_llm_classify_sync()` → raum-basierte LLM-Abfrage +3. `adapter.py:475`: Logtext aktualisieren +4. Tests: 2 neue Tests für raum-basierte LLM-Klassifikation + +--- + +### Task 1: LLM-Stufe im Classifier auf Raum-Prompt umstellen + +**Objective:** `_llm_classify_sync()` fragt das LLM nach dem Ziel-Raum, nicht nach der Kategorie. + +**Files:** +- Modify: `~/projekte/Hermes_rocket.chat_Plugin/plugin/archivar/classifier.py:346-361` +- Modify: `~/projekte/Hermes_rocket.chat_Plugin/plugin/archivar/classifier.py:509-511` (Aufruf von `_llm_classify_sync`) + +**Kontext für Implementierer:** + +Der `MessageClassifier` hat aktuell zwei LLM-Methoden: +- `_llm_classify_sync(text)` → verwendet `LLM_CLASSIFY_PROMPT`, validiert gegen FAKT/FRAGE/ALARM +- `_llm_raw_sync(prompt)` → generischer Prompt, keine Validierung (verwendet von `router._llm_room_lookup()`) + +Die `_llm_classify_sync()` wird in `_classify_sync():509-511` als Stufe 2 aufgerufen, wenn die Embedding-Konfidenz unter `LLM_CONFIDENCE_THRESHOLD` (0.70) liegt. Aktuell fragt sie: „Welche Kategorie?" und validiert gegen FAKT/FRAGE/ALARM. + +**Änderung:** Stattdessen soll sie den `LLM_ROOM_PROMPT` verwenden und eine `Optional[RoomEntry]` zurückgeben (oder None bei Fehler/kein Match). Der Aufrufer `_classify_sync()` muss das Ergebnis entsprechend verarbeiten. + +**Genauer Ablauf:** + +Schritt 1: `_llm_classify_sync()` umbenennen in `_llm_room_classify_sync()` — klarer Name. + +Schritt 2: Signatur ändern von `Optional[str]` (Kategorie) zu etwas, das ein Raum-Match signalisiert. Da der Raum-Match erst im Router interpretiert werden kann (braucht RoomMap), geben wir einen Typ zurück, den der Router versteht. Einfachste Lösung: `Optional[str]` — der Raum-Name oder `"CATCH_ALL"` oder `None` bei Fehler. + +Schritt 3: Den Prompt aus `LLM_CLASSIFY_PROMPT` durch `LLM_ROOM_PROMPT` ersetzen. Die Raum-Liste muss dynamisch gebaut werden — das passiert bereits in `router._llm_room_lookup()`. Um Dopplung zu vermeiden: Die Methode nimmt eine `room_list: str` als Parameter. + +Schritt 4: Der Aufrufer `_classify_sync():509-511` muss die `room_list` aus dem Router holen. Dafür braucht der Classifier eine Referenz zum Router — oder (einfacher) der Router ruft die LLM-Stufe selbst auf, was er bereits tut in `_llm_room_lookup()`. + +**Entscheidung: Keine Änderung an `classifier.py` — der Router macht bereits das Richtige.** + +Der Router-Flow (`router.py:152-296`) ist korrekt: +1. Schritt 1.5: Keyword-Match aus RoomMap ✅ +2. Schritt 2: Embedding-Klassifikation (Kategorie) ✅ +3. Schritt 3: Fallback bei Classifier-Versagen ✅ +4. Schritt 4: Konfidenz-Prüfung ✅ +5. Schritt 5: FAKT → doc_store ✅ +6. **Schritt 6: LLM-Room-Lookup für FRAGE** ✅ — `_llm_room_lookup()` nutzt `LLM_ROOM_PROMPT` + +Die `_llm_classify_sync()` im Classifier ist ein **paralleler Pfad**, der in `_classify_sync():509-511` aufgerufen wird, wenn die Embedding-Konfidenz niedrig ist. Das Problem: Dieser Pfad fragt nach Kategorien, nicht Räumen. Er wird also ein Kategorie-Ergebnis liefern (z.B. "FRAGE"), das dann vom Router in Schritt 6 erneut per LLM nach Räumen interpretiert wird. Das ist doppelte Arbeit und ineffizient. + +**Lösung statt Umbau:** `_llm_classify_sync()` wird NICHT mehr aufgerufen. Der `LLM_CONFIDENCE_THRESHOLD`-Zweig in `_classify_sync()` (Zeilen 509-528) wird entfernt. Wenn die Embedding-Konfidenz niedrig ist, gibt der Classifier das beste Embedding-Ergebnis zurück — der Router macht dann in Schritt 4+6 den LLM-Room-Lookup. + +**Das spart einen LLM-Call pro Nachricht und eliminiert den falschen Prompt-Pfad komplett.** + +### Step 1: LLM_CONFIDENCE_THRESHOLD-Zweig in `_classify_sync()` entfernen + +In `classifier.py:499-528`: + +```python + # Prüfe, ob die Embedding-Konfidenz ausreicht + if best_score >= LLM_CONFIDENCE_THRESHOLD: + return ClassificationResult( + category=best_category, + confidence=best_score, + all_scores=scores, + latency_ms=latency_ms, + fallback=False, + ) + + # Stufe 2: LLM-Klassifikation, wenn Konfidenz niedrig ist + if self._llm_enabled and best_score < LLM_CONFIDENCE_THRESHOLD and self._llm_client: + llm_category = self._llm_classify_sync(text) + if llm_category: + latency_ms = (time.monotonic() - t0) * 1000.0 + return ClassificationResult( + category=llm_category, + confidence=0.95, + all_scores=scores, + latency_ms=latency_ms, + fallback=False, + ) + + # Ansonsten: originales Embedding-Ergebnis zurückgeben + return ClassificationResult( + category=best_category, + confidence=best_score, + all_scores=scores, + latency_ms=latency_ms, + fallback=False, + ) +``` + +Ersetzen durch: + +```python + # Embedding-Ergebnis zurückgeben — Router macht LLM-Room-Lookup bei FRAGE. + return ClassificationResult( + category=best_category, + confidence=best_score, + all_scores=scores, + latency_ms=latency_ms, + fallback=False, + ) +``` + +**Verification:** Keine funktionale Änderung für ALARM (Keyword-Prefilter fängt das vor Embedding). Für FAKT/FRAGE mit niedriger Konfidenz: Router macht in Schritt 4+6 was nötig ist — Catch-All bei niedriger Konfidenz, LLM-Room-Lookup bei FRAGE. + +**Step 2: Run existing tests** + +Run: `cd ~/projekte/Hermes_rocket.chat_Plugin && python3 -m pytest plugin/archivar/tests/ -v` +Expected: 12 passed (bestehende Tests bleiben bestehen) + +**Step 3: Commit** + +```bash +cd ~/projekte/Hermes_rocket.chat_Plugin +git add plugin/archivar/classifier.py +git commit -m "refactor(archivar): remove LLM_CLASSIFY_PROMPT path from classifier + +Router handles LLM room lookup in step 6 (via LLM_ROOM_PROMPT). +Removing the parallel LLM_CLASSIFY_PROMPT call in _classify_sync() +eliminates a redundant LLM invocation and the wrong prompt path." +``` + +--- + +### Task 2: Gateway-Logtext aktualisieren + +**Objective:** `adapter.py`-Logtext sagt „Thematischer Raum-Router", nicht „Embedding-basierte Klassifikation". + +**Files:** +- Modify: `~/projekte/Hermes_rocket.chat_Plugin/plugin/adapter.py:475` + +**Step 1: Logtext ändern** + +In `adapter.py:475`: +```python +logger.info("[rocketchat] Archivar initialisiert — Embedding-basierte Nachrichten-Klassifikation aktiv") +``` + +Ersetzen durch: +```python +logger.info("[rocketchat] Archivar initialisiert — Thematischer Raum-Router aktiv (room-map.json)") +``` + +**Step 2: Commit** + +```bash +cd ~/projekte/Hermes_rocket.chat_Plugin +git add plugin/adapter.py +git commit -m "docs(archivar): update gateway log text to reflect room router architecture" +``` + +--- + +### Task 3: Deprecated `LLM_CLASSIFY_PROMPT` markieren + +**Objective:** Klar dokumentieren, dass `LLM_CLASSIFY_PROMPT` nicht mehr verwendet wird (nur für Abwärtskompatibilität). + +**Files:** +- Modify: `~/projekte/Hermes_rocket.chat_Plugin/plugin/archivar/config.py:129-139` + +**Step 1: Prompt-Kommentar aktualisieren** + +`config.py:129`: +```python +LLM_CLASSIFY_PROMPT = """Klassifiziere... +``` +Ergänzen zu: +```python +# DEPRECATED: Nicht mehr aktiv verwendet. Router nutzt LLM_ROOM_PROMPT (unten). +# Bleibt für externe Skripte/Abwärtskompatibilität. +LLM_CLASSIFY_PROMPT = """Klassifiziere... +``` + +**Step 2: Commit** + +```bash +cd ~/projekte/Hermes_rocket.chat_Plugin +git add plugin/archivar/config.py +git commit -m "docs(archivar): mark LLM_CLASSIFY_PROMPT as deprecated" +``` + +--- + +### Task 4: Test für Raum-basiertes LLM-Routing + +**Objective:** Sicherstellen, dass `router._llm_room_lookup()` korrekt funktioniert und Räume aus der RoomMap matcht. + +**Files:** +- Modify: `~/projekte/Hermes_rocket.chat_Plugin/plugin/archivar/tests/test_room_map.py` (erweitern) + +**Step 1: Test schreiben** + +```python +def test_llm_room_lookup_returns_correct_room(): + """LLM room lookup should match a room by its name in the response.""" + from ..room_map import RoomMap, RoomEntry + from ..router import MessageRouter + from ..classifier import MessageClassifier + + # Build a minimal RoomMap + rooms = { + "room1": RoomEntry( + room_id="room1", + name="#Rocketchat-Plugin", + theme="Plugin development", + keywords=["plugin", "adapter"], + catch_all=False, + ), + "room2": RoomEntry( + room_id="room2", + name="#BAT-Team", + theme="Trading platform", + keywords=["trading", "docker"], + catch_all=False, + ), + "room3": RoomEntry( + room_id="room3", + name="DM mit Andreas", + theme="Admin catch-all", + keywords=[], + catch_all=True, + ), + } + room_map = RoomMap( + rooms=rooms, + excluded_room_ids=set(), + fact_store_path="/tmp/archivar_test", + version=1, + ) + + router = MessageRouter( + room_map=room_map, + classifier=MessageClassifier(), # not initialized — LLM lookup is independent + ) + + # Mock the classifier's _llm_raw_sync to return a room name + calls = [] + def fake_llm(prompt): + calls.append(prompt) + return "#Rocketchat-Plugin" + + router._classifier._llm_raw_sync = fake_llm + router._classifier._llm_enabled = True + router._classifier._llm_client = True # truthy check + + result = router._llm_room_lookup("Das Plugin deployed nicht") + + assert result is not None + assert result.name == "#Rocketchat-Plugin" + assert result.room_id == "room1" + assert len(calls) == 1 + # Prompt should contain room list + assert "#Rocketchat-Plugin" in calls[0] + assert "#BAT-Team" in calls[0] + # Catch-all should not be listed as a room option + assert "DM mit Andreas" not in calls[0].split("CATCH_ALL:")[0] + + +def test_llm_room_lookup_returns_none_for_catch_all(): + """LLM returning CATCH_ALL should result in None (router falls back to catch-all).""" + from ..room_map import RoomMap, RoomEntry + from ..router import MessageRouter + from ..classifier import MessageClassifier + + rooms = { + "room1": RoomEntry("room1", "#Test", "Testing", ["test"], False), + "catch": RoomEntry("catch", "Admin", "Catch-all", [], True), + } + room_map = RoomMap(rooms=rooms, excluded_room_ids=set(), fact_store_path="/tmp", version=1) + router = MessageRouter(room_map=room_map, classifier=MessageClassifier()) + + router._classifier._llm_raw_sync = lambda p: "CATCH_ALL" + router._classifier._llm_enabled = True + router._classifier._llm_client = True + + result = router._llm_room_lookup("irgendwas unklares") + assert result is None # None → router falls back to catch_all +``` + +**Step 2: Tests ausführen** + +Run: `cd ~/projekte/Hermes_rocket.chat_Plugin && python3 -m pytest plugin/archivar/tests/test_room_map.py -v` +Expected: 14 passed (12 bestehend + 2 neu) + +**Step 3: Commit** + +```bash +cd ~/projekte/Hermes_rocket.chat_Plugin +git add plugin/archivar/tests/test_room_map.py +git commit -m "test(archivar): add LLM room lookup tests for thematic router" +``` + +--- + +### Task 5: Integrationstest — End-to-End Routing + +**Objective:** Sicherstellen, dass der gesamte Router-Flow ein korrektes Ergebnis liefert. + +**Step 1: Integrationstest schreiben** + +```python +async def test_route_keyword_match_before_llm(): + """Keyword match should skip embedding and LLM entirely.""" + from ..room_map import RoomMap, RoomEntry + from ..router import MessageRouter + from ..classifier import MessageClassifier + + rooms = { + "plugin_room": RoomEntry("plugin_room", "#Plugin", "Plugin dev", ["plugin", "archivar"], False), + "catch": RoomEntry("catch", "Catch-All", "Admin", [], True), + } + room_map = RoomMap(rooms=rooms, excluded_room_ids=set(), fact_store_path="/tmp", version=1) + classifier = MessageClassifier() + router = MessageRouter(room_map, classifier) + + # Don't initialize classifier — keyword match should work without it + decision = await router.route("Das Plugin hat einen Bug im Archivar", "some_room") + + assert decision.target_room == "plugin_room" + assert decision.matched_room_name == "#Plugin" + assert decision.confidence == 0.95 + assert not decision.is_catch_all + + +async def test_route_fakt_to_doc_store(): + """FAKT messages should never be routed to a chat room.""" + from ..room_map import RoomMap, RoomEntry + from ..router import MessageRouter + from ..classifier import MessageClassifier + + rooms = { + "catch": RoomEntry("catch", "Catch-All", "Admin", [], True), + } + room_map = RoomMap(rooms=rooms, excluded_room_ids=set(), fact_store_path="/tmp", version=1) + classifier = MessageClassifier() + await classifier.initialize() + router = MessageRouter(room_map, classifier) + + # Force classifier to return FAKT + original = classifier._classify_sync + classifier._classify_sync = lambda t: type('obj', (object,), { + 'category': 'FAKT', 'confidence': 0.9, 'all_scores': {}, 'latency_ms': 0.0, + 'is_confident': lambda self, threshold: True, + })() + + decision = await router.route("System ist online. Alle Container laufen.", "some_room") + + assert decision.category == "FAKT" + assert decision.target_room == "" # No room — goes to doc_store + assert decision.is_unrouteable +``` + +Speichern unter: `plugin/archivar/tests/test_router.py` (neue Datei) + +**Step 2: Tests ausführen** + +Run: `cd ~/projekte/Hermes_rocket.chat_Plugin && python3 -m pytest plugin/archivar/tests/test_router.py -v` +Expected: 2 passed + +**Step 3: Commit** + +```bash +cd ~/projekte/Hermes_rocket.chat_Plugin +git add plugin/archivar/tests/test_router.py +git commit -m "test(archivar): integration tests for end-to-end routing flow" +``` + +--- + +## Verfikation nach Implementation + +1. **Alle Tests:** `python3 -m pytest plugin/archivar/tests/ -v` → 16 passed +2. **Deployment:** `./install.sh --update-only` auf Build-VM +3. **Gateway-Log prüfen:** `journalctl --user -u hermes-gateway | grep "Archivar initialisiert"` → „Thematischer Raum-Router aktiv" +4. **LLM-Stufe prüfen:** `journalctl --user -u hermes-gateway | grep -i "LLM room lookup"` → erscheint bei FRAGE-Nachrichten mit niedriger Embedding-Konfidenz + +--- + +## Risiken + +- **Keine:** Der Router-Flow (`router.py:152-296`) bleibt unverändert. Nur der redundante LLM-Pfad im Classifier wird entfernt. Bestehende Tests bleiben bestehen. +- **LLM-Latenz:** `qwen2.5:7b` braucht ~2-5 Sekunden pro Call. Das passiert nur bei FRAGE-Nachrichten mit niedriger Embedding-Konfidenz (selten). Keyword-Matches (Schritt 1.5) und Catch-All (Schritt 4) sind LLM-frei. + +--- + +## Offene Punkte (nicht in diesem Plan) + +- **`install.sh` um `room-map.json`-Deployment erweitern:** Aktuell deployt `--update-only` nur den `plugin/`-Baum. Die `room-map.json` unter `~/.hermes/hermes-agent/data/` wird nicht deployed. Sollte in einem separaten Plan behandelt werden. +- **Menschlicher Override (`!r `):** In `1bb3f52` spezifiziert, noch nicht implementiert. diff --git a/install.sh b/install.sh index 95eaba1..cfe54cc 100755 --- a/install.sh +++ b/install.sh @@ -363,19 +363,9 @@ perform_update() { copied_count=$(find "$script_dir/plugin" -type f ! -path '*/__pycache__/*' ! -name '*.pyc' | wc -l) msg copied "$copied_count" - # Deploy room-map.json if it exists - local DATA_DST="$hermes_dir/data" - if [ -f "$script_dir/room-map.json" ]; then - mkdir -p "$DATA_DST" - local ROOM_MAP_DST="$DATA_DST/room-map.json" - if [ -f "$ROOM_MAP_DST" ]; then - # Create backup of existing room-map.json - cp "$ROOM_MAP_DST" "$ROOM_MAP_DST.backup.$(date +%s)" - msg room_map_backup "$ROOM_MAP_DST.backup.$(date +%s)" - fi - cp "$script_dir/room-map.json" "$ROOM_MAP_DST" - msg room_map_deployed "$ROOM_MAP_DST" - fi + # NOTE: room-map.json is MACHINE-SPECIFIC — never deployed + # by the installer. It is created by the RC-Skill onboarding + # flow after gateway start. See RC-Skill: "Room Topic Discipline" fi # Execute backend checks directly (Ollama check from lines 429-446) @@ -485,19 +475,9 @@ perform_update_only() { return 1 fi - # 3.5. Deploy room-map.json if it exists - local DATA_DST="$hermes_dir/data" - if [ -f "$script_dir/room-map.json" ]; then - mkdir -p "$DATA_DST" - local ROOM_MAP_DST="$DATA_DST/room-map.json" - if [ -f "$ROOM_MAP_DST" ]; then - # Create backup of existing room-map.json - cp "$ROOM_MAP_DST" "$ROOM_MAP_DST.backup.$(date +%s)" - msg room_map_backup "$ROOM_MAP_DST.backup.$(date +%s)" - fi - cp "$script_dir/room-map.json" "$ROOM_MAP_DST" - msg room_map_deployed "$ROOM_MAP_DST" - fi + # NOTE: room-map.json is MACHINE-SPECIFIC — never deployed + # by --update-only. It is created by the RC-Skill onboarding + # flow after gateway start. See RC-Skill: "Room Topic Discipline" # 4. Clear stale __pycache__ find "$PLUGIN_DST" -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true diff --git a/plugin/adapter.py b/plugin/adapter.py index f41a71c..602f4a6 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -581,7 +581,12 @@ class RocketChatAdapter(BasePlatformAdapter): logger.debug("[rocketchat] Archivar classification skipped: %s", e) # Forward-Antwort-Umleitung - if decision and hasattr(decision, 'target_room') and decision.target_room and decision.target_room != room_id: + # Nur umleiten, wenn der Zielraum subscribed ist (nicht unrouteable). + # is_unrouteable=True bedeutet: target_room ist nicht in den Bot-Subscriptions; + # dann im Ursprungsraum bleiben und dort antworten. + if (decision and hasattr(decision, 'target_room') and decision.target_room + and decision.target_room != room_id + and not getattr(decision, 'is_unrouteable', False)): _CURRENT_ORIGIN_ROOM.set(decision.target_room) try: note_text = f"Ich antworte im {getattr(decision, 'matched_room_name', None) or 'Zielraum'}." @@ -597,8 +602,10 @@ class RocketChatAdapter(BasePlatformAdapter): # Both get the same session key. virtual_chat_id = f"user:{username}" # Track the REAL room for send() to route the response back - # Only set if no forwarding occurred - if not (decision and hasattr(decision, 'target_room') and decision.target_room and decision.target_room != room_id): + # Only set if no forwarding occurred (or forwarding was unrouteable) + if not (decision and hasattr(decision, 'target_room') and decision.target_room + and decision.target_room != room_id + and not getattr(decision, 'is_unrouteable', False)): _CURRENT_ORIGIN_ROOM.set(room_id) # Ensure this user→room mapping is recorded for proaktive sends diff --git a/room-map.json b/room-map.json deleted file mode 100644 index c0673ea..0000000 --- a/room-map.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": 1, - "rooms": { - "GENERAL": { - "name": "#general", - "theme": "General discussion", - "keywords": ["general", "discussion"], - "catch_all": true - } - }, - "excluded_rooms": [] -} \ No newline at end of file