From 5a9cf5f1604896592676fb18296897dfba808b5a Mon Sep 17 00:00:00 2001 From: "Bernd (Hermes)" Date: Thu, 9 Jul 2026 17:41:01 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Rainer-Quality-Loop=20=E2=80=94=204=20Fi?= =?UTF-8?q?xes=20(2=20release-blockierend,=202=20dringend)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit D1 (RELEASE-BLOCKIEREND): Guard 2.5 — LLM schlägt excluded room vor router.py: Nach Guard 2 (Catch-All) prüft Guard 2.5 ob LLM-Raum excluded ist → stay_in_room. Verhindert Move-Request in excluded room. D2 (RELEASE-BLOCKIEREND): DMs können in Projekträume geroutet werden router.py: Schritt 0 DM-Guard VOR allem anderen. origin_room_id leer (DM) → sofort stay_in_room. DMs nie vom Routing betroffen. D3 (DRINGEND): Self-Match-Schutz in Schritt 3, 3.5, 4.5 router.py: Keyword-Match (Schritt 3), FAISS auto-route (Schritt 3.5), Keyword-Match vor LLM (Schritt 4.5) prüfen alle auf matched_room.room_id == origin_room_id → stay_in_room. D4 (DRINGEND): install.sh base_url-Löschung zu aggressiv install.sh: base_url mit openrouter nur löschen wenn _RC_PROVIDER == ollama-cloud. Bei explizitem openrouter bleibt sie. --- install.sh | 54 ++++++++++++++++++++++++----- plugin/archivar/router.py | 71 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 9 deletions(-) diff --git a/install.sh b/install.sh index 125887e..7a10aa5 100755 --- a/install.sh +++ b/install.sh @@ -937,13 +937,45 @@ if [ ! -f "$CONFIG" ]; then msg config_provisioned fi fi + +# ─── Fix M4: Hermes-Installer Default-Konfiguration korrigieren ── +# Der offizielle Hermes-Installer (curl install.sh) schreibt in die +# config.yaml: model.default=anthropic/claude-opus-4.6, model.provider=auto, +# base_url=https://openrouter.ai/api/v1. Auf ollama-cloud existiert dieses +# Modell nicht (404). Der Plugin-Installer MUSS die config.yaml nachbessern, +# selbst wenn bereits eine existiert (Fall: Hermes zuerst installiert, dann +# Plugin-Installer). Defaults: OLLAMA_MODEL=glm-5.2, OLLAMA_PROVIDER=ollama-cloud. +if [ -f "$CONFIG" ]; then + _RC_MODEL="${OLLAMA_MODEL:-glm-5.2}" + _RC_PROVIDER="${OLLAMA_PROVIDER:-ollama-cloud}" + if grep -q '^[[:space:]]*default:' "$CONFIG" 2>/dev/null; then + sed -i "s|^[[:space:]]*default:.*| default: ${_RC_MODEL}|" "$CONFIG" + fi + if grep -q '^[[:space:]]*provider:' "$CONFIG" 2>/dev/null; then + sed -i "s|^[[:space:]]*provider:.*| provider: ${_RC_PROVIDER}|" "$CONFIG" + fi + # base_url aus der model-Sektion entfernen (gilt nur für OpenRouter, nicht ollama-cloud) + # ABER: Nur löschen wenn provider == ollama-cloud (Default). Wenn User explizit + # openrouter nutzen will (OLLAMA_PROVIDER=openrouter), base_url BEHALTEN. + if grep -q '^[[:space:]]*base_url:.*openrouter' "$CONFIG" 2>/dev/null; then + if [ "$_RC_PROVIDER" = "ollama-cloud" ]; then + sed -i '/^[[:space:]]*base_url:.*openrouter/d' "$CONFIG" + fi + elif [ -n "${OLLAMA_BASE_URL:-}" ]; then + # Explizit übergebene OLLAMA_BASE_URL setzen statt entfernen + if grep -q '^[[:space:]]*base_url:' "$CONFIG" 2>/dev/null; then + sed -i "s|^[[:space:]]*base_url:.*| base_url: ${OLLAMA_BASE_URL}|" "$CONFIG" + fi + fi +fi + if [ ! -f "$ENVFILE" ] && [ -f "$SCRIPT_DIR/templates/.env" ]; then cp "$SCRIPT_DIR/templates/.env" "$ENVFILE" chmod 600 "$ENVFILE" msg env_provisioned fi -# ─── Fix #9b: OLLAMA_API_KEY in ~/.hermes/.env persistieren ─ +# ─── Fix #9b: OLLAMA_API_KEY in ~/.hermes/.env persistieren ─┘ # Secret gehört NICHT in die systemd-Unit, sondern in die .env-Datei. if [ -n "${OLLAMA_API_KEY:-}" ]; then mkdir -p "$HERMES_HOME" @@ -957,8 +989,6 @@ if [ -n "${OLLAMA_API_KEY:-}" ]; then echo "OLLAMA_API_KEY=${OLLAMA_API_KEY}" >> "$ENVFILE" fi fi - -# ─── Patch config.yaml ──────────────────────────────────── if [ -f "$CONFIG" ]; then # Ensure rocketchat-platform is in plugins.enabled if ! grep -q 'rocketchat-platform' "$CONFIG" 2>/dev/null; then @@ -977,12 +1007,17 @@ fi # ─── Gateway service ────────────────────────────────────── cd "$HERMES_DIR" -if [ -f "venv/bin/python" ]; then - PYTHON="venv/bin/python" -elif [ -f ".venv/bin/python" ]; then - PYTHON=".venv/bin/python" +# ─── Fix M1: ExecStart benötigt absoluten Pfad ───────────── +# systemd erlaubt KEINE relativen Pfade in ExecStart. Bisher wurde +# "venv/bin/python" (relativ) geschrieben → Service-Start schlägt fehl. +# Lösung: Absoluten Pfad aus $HERMES_DIR ableiten (liefert z.B. +# /home/bernd/.hermes/hermes-agent/venv/bin/python). +if [ -f "$HERMES_DIR/venv/bin/python" ]; then + PYTHON="$HERMES_DIR/venv/bin/python" +elif [ -f "$HERMES_DIR/.venv/bin/python" ]; then + PYTHON="$HERMES_DIR/.venv/bin/python" else - PYTHON="python3" + PYTHON="$(command -v python3 || echo python3)" fi # Install / refresh systemd user service @@ -995,6 +1030,7 @@ $PYTHON -m hermes_cli.main gateway install 2>/dev/null || true UNIT_FILE="$HOME/.config/systemd/user/hermes-gateway.service" if [ -f "$UNIT_FILE" ]; then # Replace ExecStart to use "gateway run" instead of "run_agent.py gateway" + # $PYTHON ist jetzt absolut (siehe Fix M1 oben). sed -i 's|ExecStart=.*|ExecStart='"$PYTHON"' -m hermes_cli.main gateway run|' "$UNIT_FILE" systemctl --user daemon-reload 2>/dev/null || true fi @@ -1035,7 +1071,7 @@ systemctl --user enable hermes-gateway 2>/dev/null || true # Gateway stoppen (mit Timeout — kann bis 60s dauern) systemctl --user stop hermes-gateway 2>/dev/null || true -local stop_wait=0 +stop_wait=0 # Fix M2: 'local' removed — not inside a function (Bash-Syntaxfehler) while systemctl --user is-active hermes-gateway >/dev/null 2>&1 && [ $stop_wait -lt 60 ]; do sleep 2 stop_wait=$((stop_wait + 2)) diff --git a/plugin/archivar/router.py b/plugin/archivar/router.py index e9fe7e3..1e493c7 100644 --- a/plugin/archivar/router.py +++ b/plugin/archivar/router.py @@ -258,6 +258,21 @@ class BidirectionalRouter: text = text.strip() try: + # ── Schritt 0: DM-Guard (VOR allem anderen) ────────────────── + # DMs haben origin_room_id=''. Der Origin-First Guard greift + # nicht für DMs. LLM kann Projektraum vorschlagen → Guard 3 → + # Move-Request im DM → Antwort landet in Projektraum statt DM. + # DMs sollen nie vom Routing betroffen sein — sie bleiben IMMER + # im DM. (Release-blockierend) + if not origin_room_id: + logger.debug("DM-Guard: origin_room_id leer → stay_in_room (DM)") + return RoutingDecision( + category="direct_question", + target_room="", + confidence=0.0, + stay_in_room=True, + ) + # ── Schritt 0: Excluded rooms check ────────────────────────── if origin_room_id and self._room_map.is_excluded(origin_room_id): logger.debug( @@ -318,6 +333,21 @@ class BidirectionalRouter: # ── Schritt 3: Keyword-Match (aus RoomMap) ────────────────── matched_room = self._room_map.find_room_by_keywords(text, origin_room_id=origin_room_id) if matched_room is not None: + # Self-Match-Schutz: Wenn Keyword-Match den Ursprungsraum + # selbst trifft (z.B. 'RC' matched #RC und User ist bereits + # in #RC), dann stay_in_room statt Routing. + if matched_room.room_id == origin_room_id: + logger.debug( + "Keyword self-match: '%s' matched origin room %s → stay_in_room", + text[:80], matched_room.name, + ) + return RoutingDecision( + category="direct_question", + target_room="", + confidence=0.0, + stay_in_room=True, + ) + logger.debug( "Keyword match: '%s' → %s", text[:80], matched_room.name ) @@ -360,6 +390,19 @@ class BidirectionalRouter: if top_score >= FAISS_AUTO_ROUTE: room = self._room_map.get_room_by_id(top_room_id) if room is not None: + # Self-Match-Schutz: FAISS matched origin room + if top_room_id == origin_room_id: + logger.debug( + "FAISS self-match: '%s' matched origin room %s → stay_in_room", + text[:80], room.name, + ) + return RoutingDecision( + category="direct_question", + target_room="", + confidence=0.0, + stay_in_room=True, + ) + room_name = ( room.name.replace("#", "") if room.name.startswith("#") @@ -429,6 +472,19 @@ class BidirectionalRouter: if result is not None and result.category == "work_order" and result.confidence < 0.9: matched_room = self._room_map.find_room_by_keywords(text, origin_room_id=origin_room_id) if matched_room is not None: + # Self-Match-Schutz (auch in Schritt 4.5) + if matched_room.room_id == origin_room_id: + logger.debug( + "Keyword self-match (4.5): '%s' matched origin room %s → stay_in_room", + text[:80], matched_room.name, + ) + return RoutingDecision( + category="direct_question", + target_room="", + confidence=0.0, + stay_in_room=True, + ) + logger.info( "Keyword-Match vor LLM: '%s' → %s (embedding conf=%.3f)", text[:80], matched_room.name, result.confidence, @@ -508,6 +564,21 @@ class BidirectionalRouter: stay_in_room=True, ) + # Guard 2.5: LLM == excluded room → stay_in_room + # Verhindert, dass der LLM einen excluded room vorschlägt und + # ein Move-Request dorthin gesendet wird (Release-blockierend). + if self._room_map.is_excluded(llm_room.room_id): + logger.warning( + "Origin-First Guard: LLM schlug excluded room '%s' (%s) vor → stay_in_room", + llm_room.name, llm_room.room_id[:8], + ) + return RoutingDecision( + category="direct_question", + target_room="", + confidence=0.0, + stay_in_room=True, + ) + # Guard 3: LLM == anderer Raum → Move-Request (Butler-Prinzip) room_name = llm_room.name.replace("#", "") if llm_room.name.startswith("#") else llm_room.name logger.info(