feat(curator): Butler-Kurator 5-stufige Pipeline (B13/B14-Fix)

5-stufige Pipeline zur proaktiven Pflege des Silent Collectors
(Konzept Analysen/Butler-Kurator-Architektur_Rainer.md):

- Stufe 1: Blocklist (4-Ebenen aus 6cbea1b, single source of truth)
- Stufe 2: Duplikats-Check (keyword in keywords_100[room])
- Stufe 3: LLM-Sicherheits-Check (1 Call/Keyword, P-165-konform,
  Fallback bei Timeout/429 -> confidence='mittel' -> Rueckfrage)
- Stufe 4: Score-Aggregation (Unsicherheits-Score, Top-N max 5)
- Stufe 5: Rueckfrage (gebuendelte Batch-Nachricht an Operator-DM)

archivar_state.py: curation_log[], last_curation_ts, last_curation_mode
+ Methoden record_curation_run, apply_curation_response,
undo_last_curation, can_curate_now (Defaults fuer Legacy-Migration).

Trigger: Hybrid (zeitbasiert Sonntag 22:00 ODER mengenbasiert >=25
pending + 24h Cooldown).

Inline-Commands: ::keywords curate, curate status, curate undo <run_id>,
curate log [N].

20 neue Unit-Tests (test_butler_curator.py), Regression gruen.

Pitfall P-188: Konzept-Score-Widerspruch aufgeloest (unsicherheit
absteigend sortiert, nicht aufsteigend).
This commit is contained in:
Bernd (Hermes)
2026-09-03 07:10:51 +02:00
parent 32b93fe7b8
commit fe9ee213f3
4 changed files with 1041 additions and 2 deletions
+88 -1
View File
@@ -6699,6 +6699,10 @@ class RocketChatAdapter(BasePlatformAdapter):
review alle ✅ — Bestätigt alle.
review alle ❌ — Verwirft alle.
status — Zeigt wieviele Stichworte pro Raum gesammelt sind.
curate — Triggert den Butler-Kurator sofort (manuell).
curate status — Zeigt last_curation_ts/mode + pending_total.
curate undo <id> — Stellt den letzten Kurator-Lauf wieder her.
curate log [N] — Zeigt die letzten N Kurationen.
"""
if not _MULTIROOM() or self.archivar is None:
return "❌ `::keywords` ist nur im Multiroom-Modus verfügbar."
@@ -6711,6 +6715,10 @@ class RocketChatAdapter(BasePlatformAdapter):
action = parts[0].lower() if parts else "review"
rest = parts[1] if len(parts) > 1 else ""
# ── :: keywords curate ─────────────────────────────────────────
if action == "curate":
return await self._cmd_keywords_curate(room_id, rest)
# ── :: keywords status ────────────────────────────────────────
if action == "status":
from archivar.inline_commands import build_keywords_status_text
@@ -6741,7 +6749,86 @@ class RocketChatAdapter(BasePlatformAdapter):
return (
f"❌ Unbekannte Option: `{sub}`\n\n"
"Verfügbar: `review`, `review ✅ <nr>`, `review ❌ <nr>`, "
"`review alle ✅`, `review alle ❌`, `status`"
"`review alle ✅`, `review alle ❌`, `status`, `curate`, "
"`curate status`, `curate undo <run_id>`, `curate log [N]`"
)
async def _cmd_keywords_curate(self, room_id: str, rest: str) -> str:
"""::keywords curate — Butler-Kurator (manueller Trigger + Status/Undo/Log)."""
state = self.archivar._state
room_map = getattr(self.archivar, "_room_map", None)
from archivar.butler_curator import ButlerCurator
# send_fn: Rückfrage an den Operator-DM (NICHT User-Räume, §6.5).
def _send_to_operator(text: str) -> None:
op_room = self._find_operator_room()
if not op_room:
logger.warning("[rocketchat] Kurator: kein Operator-DM — Rückfrage verworfen")
return
try:
self.post_message(op_room, text)
except Exception as e:
logger.warning("[rocketchat] Kurator: Rückfrage-Send fehlgeschlagen: %s", e)
curator = ButlerCurator(state=state, room_map=room_map, send_fn=_send_to_operator)
sub = rest.strip()
parts = sub.split(None, 1)
sub_action = parts[0].lower() if parts else ""
sub_rest = parts[1] if len(parts) > 1 else ""
# ── :: keywords curate (ohne Subcommand) → Lauf triggern ──────
if not sub_action:
run_id = curator.run_curation(trigger_mode="manual", trigger_reason="inline command")
if run_id is None:
return "⏸️ Kurator übersprungen (Cooldown aktiv oder keine pending Keywords)."
return f"🤖 Butler-Kurator-Lauf gestartet. `run_id`: `{run_id}`"
# ── :: keywords curate status ─────────────────────────────────
if sub_action == "status":
s = curator.get_status()
ts = s.get("last_curation_ts") or "nie"
mode = s.get("last_curation_mode") or "—"
return (
f"📋 **Butler-Kurator Status**\n\n"
f"- Letzter Lauf: {ts}\n"
f"- Modus: {mode}\n"
f"- Pending Keywords gesamt: {s.get('pending_total', 0)}"
)
# ── :: keywords curate undo <run_id> ──────────────────────────
if sub_action == "undo":
if not sub_rest:
return "❌ Bitte gib die `run_id` an: `:: keywords curate undo <run_id>`."
result = curator.undo_last_curation(sub_rest.strip())
if not result.get("ok"):
return f"❌ Undo fehlgeschlagen: {result.get('error', 'unbekannt')}"
return f"✅ {result.get('restored', 0)} Keyword(s) wiederhergestellt."
# ── :: keywords curate log [N] ────────────────────────────────
if sub_action == "log":
try:
n = int(sub_rest) if sub_rest else 5
except ValueError:
return f"❌ Ungültige Anzahl: `{sub_rest}`."
entries = curator.get_log(n)
if not entries:
return "📋 Keine Kurator-Läufe protokolliert."
lines = ["📋 **Butler-Kurator Log**", ""]
for e in entries:
stats = e.get("stats", {})
lines.append(
f"- `{e.get('run_id')}` ({e.get('mode')}) — "
f"{stats.get('pending_total', 0)} pending, "
f"{len(e.get('verworfen', []))} verworfen, "
f"{len(e.get('rueckfrage', []))} Rückfrage"
)
return "\n".join(lines)
return (
f"❌ Unbekannte Option: `{sub}`\n\n"
"Verfügbar: `curate`, `curate status`, `curate undo <run_id>`, `curate log [N]`"
)
async def _evaluate_pending_keywords(self, room_id: str, rest: str) -> str: