Commit Graph

22 Commits

Author SHA1 Message Date
Bernd (Hermes) 6f47885b1c fix(install.sh): numpy, circular import, room-map.json, archivar symlink in hermes root
FIX 1: numpy/faiss-cpu pip install in venv nach Plugin-Deployment
       in allen drei Pfaden (perform_update, perform_update_only,
       main interactive). Archivar braucht diese Packages für
       FAISS Phase-1 RoomIndex — ohne sie crasht der Import.

FIX 2: Zirkelimport adapter.py ↔ archivar/adapter_integration.py
       gebrochen. _room_context/_room_context_lock werden jetzt
       lazy innerhalb handle_feedback_response() importiert.

FIX 3: Minimale room-map.json (version=1, rooms={}) wird als
       Template bereitgestellt und bei Clean-Install ins
       Datenverzeichnis kopiert. RC-Skill-Onboarding erstellt
       die vollständige, maschinen-spezifische Version.

FIX 4: Archivar-Symlink liegt bereits korrekt im HERMES_DIR
       (Commit 5c8026c). Keine Änderung nötig.
2026-06-22 12:47:50 +02:00
Bernd (Hermes) 4d6fae6bf7 fix(archivar): is_stale()-Check in initialize() — FAISS-Index erkennt Keyword-Updates in room-map.json
P45-Fix: Nach load() wird is_stale() geprüft. Wenn die RoomMap-Version
neuer ist als der gespeicherte Index, wird automatisch rebuild + save
ausgeführt. Verhindert, dass Keyword-Änderungen in room-map.json erst
nach manuellem Löschen der .faiss/.meta-Dateien wirken.
2026-06-21 08:06:17 +02:00
Bernd (Hermes) 0e13e4b30d fix(archivar): ContextVar→global dict, asyncio.to_thread, EMBEDDING_BASE_URL, FAISS_AUTO_ROUTE=0.55
- adapter.py: ContextVars durch globales _room_context dict + threading.Lock ersetzt
  (Agent-Task sieht jetzt Archivar-Zielraum — kein error-not-allowed mehr)
- adapter_integration.py: Stay-Feedback-Handler leert thematic_target
  (verhindert dass nächster Send auf alten Archivar-Vorschlag fällt)
- classifier.py: _llm_raw() nutzt asyncio.to_thread() statt direktem await
  (LLMClient.generate() ist synchron — vorher TypeError)
- config.py: ARCHIVAR_EMBEDDING_BASE_URL trennt Embeddings von Chat-URL
  (OLLAMA_BASE_URL-Kollision behoben). FAISS_AUTO_ROUTE 0.70→0.55
  (mehr Nachrichten durch Booster statt direktem FAISS-Routing)
2026-06-19 09:09:17 +02:00
Bernd (Hermes) 8d6deb7f2d feat(archivar): RoutingWiderspruchDetector — textbasierte Widerspruch-Erkennung
NEUES MODUL: plugin/archivar/feedback_detector.py
- RoutingWiderspruchDetector mit 4 Regex-Gruppen (Hauptmuster, Umrouting,
  Verneinung, Befehle)
- ContradictionResult dataclass: has_contradiction, contradiction_type,
  confidence, target_room, rejected_room, matched_pattern
- Edge Cases: 'nicht in X, sondern in Y' → X negativ, Y als Ziel
- Kein LLM-Fallback (nur Regex in v1)

EINHAENGUNG adapter_integration.py:
- ArchivarMessageHandler.__init__(): self._feedback_detector
- detect_routing_contradiction(text, origin_room_id) → ContradictionResult|None
- Bei Treffer: update_keyword_weight(feedback_type='never')
- _resolve_room_name_to_id() für Raum-Name → room_id Auflösung

EINHAENGUNG adapter.py:
- _process_incoming(): VOR classify_and_route() → contradiction-Check
- Bei Treffer: Decision überschreiben (stay_in_room=True)
- [WIDERSPRUCH]-Präfix — Nachricht NICHT schlucken, normal an Agent
- NUR wenn KEIN Button-Feedback aktiv (kein pending move-request)

Tests: 57/58 passed (1 pre-existing env-var failure unverändert)
2026-06-18 06:21:24 +02:00
Bernd (Hermes) 7776e26fb2 FAISS index persistence: load() before build_index(), save() after build
- initialize() now tries load() from disk first
- If load succeeds: log 'Index von Disk geladen' + wire router
- If load fails: build_index() + save() + log 'Index gebaut + gespeichert' + wire router
- Eliminates unnecessary index rebuild on every gateway restart
- All 58 tests pass
2026-06-16 21:07:37 +02:00
Bernd (Hermes) d54c9a8896 fix(archivar): add StreamHandler to adapter_integration logger
setLevel(INFO) alone was not enough — without a handler and with
propagate=True (default), logs were accepted by the root logger
(level WARNING) but silently discarded since root has no handlers.

Now matches adapter.py pattern: StreamHandler + propagate=False,
so all submodule logs (classifier, router, room_index, booster)
are visible via the shared parent logger.
2026-06-16 20:42:01 +02:00
Bernd (Hermes) 0b4ff2169e fix(archivar): set logger level to INFO in adapter_integration.py
Root logger defaults to WARNING (level 30) when no basicConfig is set.
adapter_integration.py only called getLogger(__name__) without setLevel,
so all INFO logs were silently filtered. adapter.py already had its own
setLevel(INFO) + handler, which is why its logs appeared.

Fix: add logger.setLevel(logging.INFO) after getLogger(__name__) at line 94.
This restores all suppressed INFO logs:
- Initializing ArchivarMessageHandler...
- FAISS Phase-1: RoomIndexManager + KeywordBooster ready
- FAISS Phase-1: Index built
- FAISS Phase-1: Router wired
- ArchivarMessageHandler ready
2026-06-16 20:38:50 +02:00
Bernd (Hermes) 03d3bb44df BUGFIX: FAISS Phase-1 TypeError float+str in adapter_integration.py:292
Root cause: RoomIndexManager.stats() returns a dict with mixed types
(bool, int, float, str). sum() iterated over all values and crashed
when hitting built_at_iso (str) after built_at (float).

Fix: Replace stats() call with direct .size and .room_ids properties.
Also commit FAISS Phase-1 files (booster.py, room_index.py, seed_data.py)
that were deployed to Gateway but not yet in repo.

Tests: 58 passed (0 failures)
2026-06-16 20:31:57 +02:00
Bernd (Hermes) 43d14b2d58 fix(archivar): FAISS Phase-1 Integration — RoomIndexManager + KeywordBooster in ArchivarMessageHandler verdrahtet
- __init__: RoomIndexManager(room_map, embedding_client) + KeywordBooster(room_map)
- initialize(): build_index() aus Seed-Daten, Router mit FAISS-Objekten neu erstellen
- Fallback: bei Fehler → None → bestehendes LLM-Verhalten
2026-06-16 19:58:15 +02:00
Bernd (Hermes) 00d6ca4e75 fix(archivar): Hardcodierte Pfade durch ROOM_MAP_PATH/DEFAULT_MAP_PATH ersetzt
check_room_map_completeness() und _load_room_map() verwendeten
hardcodierte Pfade (~/.hermes/hermes-agent/data/room-map.json)
statt der Konstanten ROOM_MAP_PATH/DEFAULT_MAP_PATH.

Das führte dazu, dass Unit-Tests die produktive room-map.json
überschrieben — der Mock-Patch auf ROOM_MAP_PATH griff nicht,
weil save() und reload() den hardcodierten Pfad verwendeten.

Fix:
- adapter_integration.py: 2 hardcodierte Pfade → ROOM_MAP_PATH
- room_map.py: Doppelte DEFAULT_MAP_PATH-Zuweisung entfernt
2026-06-15 20:07:05 +02:00
Bernd (Hermes) 80842a365e fix(archivar): Move-Request-Zielraum an _CURRENT_ORIGIN_ROOM übergeben
ZWEI-PUNKT-FIX (Miguel):

1. adapter_integration.py (Zeile 458-466):
   _send_move_request() übergibt jetzt _move_request-Payload an
   den Button-Send-Callback — mit target_room, target_name, text.

2. adapter.py _send_archivar_buttons (Zeile 978-1004):
   Erkennt den _move_request-Payload, befüllt _pending_move_requests,
   verwendet MOVE_REQ:: Separator für korrektes Button-Parsing.

3. adapter.py Move-Request-Handler (Zeile 739):
   Akzeptiert 'confirm_move' und '✅ja' als Routing-Trigger.

Flow: Archivar v4 → _send_move_request → _send_archivar_buttons
→ _pending_move_requests gesetzt → ✅Ja-Button → Response-Handler
findet pending request → _CURRENT_ORIGIN_ROOM auf Zielraum gesetzt ✓
2026-06-14 16:14:48 +02:00
Bernd (Hermes) 170f7e6096 feat(archivar): LLM-basierter Raum-Router ersetzt IntentClassifier — Embedding-Vorfilter + LLM_ROOM_PROMPT + Move-Request-Buttons
Korrigierter Archivar-Routing-Flow gemäß Architekturskizze:

1. Embedding-Vorfilter (nomic-embed-text): binär Smalltalk vs. potenzieller Auftrag
   - Klarer Smalltalk → stay_in_room
   - Unsicher → LLM-Raum-Router

2. LLM-Raum-Router (qwen2.5:7b): LLM_ROOM_PROMPT als zentraler Prompt
   - Erhält Nachrichtentext + Raumliste mit IDs und ALLEN Keywords
   - Liefert room_id direkt (keine Kategorien, kein Name-Matching)

3. Move-Request-Buttons (Butler-Prinzip): ✅Ja/📍Hier VOR Routing
   - Kein automatisches Routing ohne User-Bestätigung

4. Betriebsstufen-Log: 'Archivar Stufe 1: Embedding-Vorfilter + LLM-Raum-Router aktiv (5 Räume)'

Änderungen:
- config.py: LLM_ROOM_PROMPT auf Raum-ID-Ausgabe umgestellt, Keywords pro Raum,
  ARCHIVAR_STUFE_LOG, MOVE_REQUEST_TEMPLATE, max_tokens=30
- classifier.py: LLMClient.generate() als neue ABC-Methode + OllamaLLMClient-Impl,
  _llm_raw_sync nutzt generate() statt classify()
- router.py: RoutingDecision um move_request_sent/target_name/target_id erweitert,
  route() komplett neu: Embedding→LLM→Move-Request, _llm_room_lookup() mit IDs+Keywords
- adapter_integration.py: _send_move_request() + handle_move_request_response(),
  classify_and_route() behandelt move_request_sent, handle_and_forward() wartet auf Bestätigung

IntentClassifier.classify() wird NICHT gelöscht — nur als binärer Vorfilter verwendet.
Bestehende Tests: 53/54 grün (1 pre-existing env-var issue).
2026-06-14 10:25:33 +02:00
Hermes Agent 4bb1ccbc82 feat(archivar): Lernsystem-Verdrahtung — Move-Request + Clarify lernen Keyword-Gewichte
- RoutingDecision um matched_keywords-Feld erweitert (router.py)
- _extract_routing_keywords-Stub entfernt, Keywords aus Decision durchreichen (adapter_integration.py)
- _routed_messages nach classify_and_route() befüllen (adapter.py)
- move_req-Dict um message_id erweitert (adapter.py)
- Move-Request-Handler: handle_feedback_response mit confirm/stay/never aufrufen (adapter.py)
- handle_clarification_response: update_keyword_weight für ambige Keywords lernen (adapter_integration.py)
- Clarify-Frage-Text: "Ich möchte mir das für die Zukunft richtig merken..." (config.py)

Feedback-Mapping: 1️⃣ Rüber=confirm, 2️⃣ Hier=stay, 3️⃣ Nein=never, 📝/💬=stay, 📋=confirm
2026-06-13 09:50:54 +02:00
Hermes Agent 6b97ccfad9 feat(archivar): Selbstlernendes Keyword-Gewicht-System (Teil 2)
- KeywordWeightEntry + ManualOverride Dataclasses in archivar_state.py
- Lernalgorithmus: confirm (+0.1), stay (-0.05), never (0.0+sticky)
- Promotion: 3 confirmations + weight ≥0.85 → keywords_100
- Degradation + zeitbasierte Abwertung (Decay: 30d -10%, 90d -30%)
- Cold-Start: Bootstrap Tag 1-7 (LR=0.2), Tag 8+ (LR=0.1)
- Gewichtetes Scoring in find_room_by_keywords()
- Feedback-Schleife in adapter_integration.py nach Move-Request-Auflösung
- 54 Tests grün (inkl. 8 neue für gewichtetes Scoring)
2026-06-12 19:57:46 +02:00
Hermes Agent dba856ffab feat(archivar): Implement Button-Garantie und ArchivarState-Integration für Archivar v3 2026-06-11 21:44:38 +02:00
Hermes Agent ad852c1642 fix(archivar): doc_store writes to fact_store_path from room_map
DocumentationStore() now uses RoomMap.fact_store_path instead of the
hardcoded ~/.hermes/.../archivar_docs default. One-line change — the
doc_store is initialized after _load_room_map() so room_map is available.

This allows per-deployment configuration: in production, fact_store_path
points to /data/Wissensdatenbank/0100 Inbox so FAKT messages land in the
Obsidian vault's inbox for StartObsidian integration.
2026-06-06 20:32:13 +02:00
Hermes Agent 8591933d8d 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).
2026-06-06 19:31:46 +02:00
Hermes Agent 58f00c0c23 feat(archivar): Phase 1-3 — RoomMap + thematischer Router
Phase 1 (Datenmodell):
- plugin/archivar/room_map.py: RoomMap, RoomEntry, RoomMapValidationError
- room-map.schema.json: JSON-Schema für room-map.json
- room-map.json: Echte Raum-IDs (RC, BAT, LAN-Doku, DM Andreas)
- config.py: LLM_ROOM_PROMPT, ROOM_MAP_PATH, deprecated-Marker

Phase 2 (Router-Umbau):
- router.py: MessageRouter nutzt RoomMap statt ROOM_MAPPING Env-Vars
  - Neue Methode _llm_room_lookup() fragt LLM: 'In welchen Raum?'
  - Keyword-Match aus RoomEntry.keywords (vor Embedding)
  - Excluded rooms check via RoomMap.is_excluded()
  - origin_room_id Parameter für Multi-Agent-Raum-Ausschluss

Phase 3 (Integration):
- adapter_integration.py: _load_room_map() mit Env-Var-Fallback
  - validate() beim Gateway-Start
  - classify_and_route() reicht origin_room_id durch
- classifier.py: _llm_raw_sync() für Room-Prompts (nicht Kategorien)

12/12 Unit-Tests bestanden ✅
2026-06-05 22:06:32 +02:00
Hermes Agent e5a32abf5c feat(archivar): dreistufiger Klassifikator — Keyword + Embedding + LLM (qwen2.5:7b)
Phase 3 (Miguel): 236 Zeilen in config.py, classifier.py, adapter_integration.py.
Phase 4 (Rainer): Quality Gate F1–F5 bestanden.

- Stufe 0: Keyword-Vorfilter mit erweiterten ALARM/FRAGE-Listen
- Stufe 1: Embedding (nomic-embed-text, Schwelle 0.70)
- Stufe 2: LLM-Klassifikation (qwen2.5:7b) für Grenzfälle
- Feature-Flag ARCHIVAR_ENABLE_LLM über Env-Variable
- LLMClient-Interface für Testbarkeit
- router.py unverändert (Blackbox-Integration)
2026-06-04 21:49:17 +02:00
Hermes Agent 886e566e77 Doc-Store: Messages in nicht abonnierte Räume werden im Filesystem abgelegt
Harte Durchsetzung: Der Archivar darf NUR in Räume routen, die der Bot
tatsächlich abonniert hat. Alles andere ist ein Architekturfehler.

Neu:
- doc_store.py: DocumentationStore — speichert unrouteable Nachrichten
  als Markdown mit YAML-Frontmatter unter data/archivar_docs/{category}/
- router.py: RoutingDecision.is_unrouteable + unrouteable_reason,
  MessageRouter.set_subscribed_room_ids(), Zielraum-Validierung
- adapter_integration.py: ArchivarMessageHandler.set_subscribed_room_ids(),
  classify_and_route() leitet bei is_unrouteable in doc_store um
- adapter.py: set_subscribed_room_ids() wird nach connect() mit den
  realen subscribed rooms gefüttert

Verhalten: Wenn jemand 'ALARM: Server down' in einem Raum schreibt,
den der Bot nicht abonniert hat, wird die Nachricht KLASSIFIZIERT,
aber NICHT geroutet — sie landet im doc_store mit Begründung.
2026-06-03 22:06:30 +02:00
Hermes Agent bb8623aed5 fix: binary corruption in adapter.py + absolute→relative imports in archivar/
- adapter.py: recopied from production (write_file corrupted the em-dash on line 8)
- All archivar/*.py: from archivar.X → from .X for plugin-context compatibility
2026-06-03 10:17:03 +02:00
Hermes Agent 88b7149dd1 feat: Archivar delivery + install.sh v2.2 — full function set
- Add archivar/ submodule to plugin/ (5 files, relative imports)
- Update adapter.py with relative Archivar import from .archivar.adapter_integration
- install.sh: fix --non-interactive env-var reading (Z.316-318, Bug #7)
- install.sh: recursive file copy (was 4 flat files, now entire plugin/ tree incl. submodules)
- install.sh: Ollama presence check + nomic-embed-text pull
- install.sh: write OLLAMA_BASE_URL to rocketchat.env
- install.sh: add new message keys (collama_check, nomic_pull, nomic_ok, nomic_fail, copied)

Closes: Archivar delivery gap (2026-06-03)
Reviewed-by: Bernd (Advisor)
2026-06-03 10:12:47 +02:00