From 14294bdf2df7633edf124b71e1d98082086fd294 Mon Sep 17 00:00:00 2001 From: Prime Backup Bot Date: Thu, 12 Mar 2026 00:20:50 +0000 Subject: [PATCH] fix(chat): return clean assistant text instead of raw codex event stream --- prime_core/telegram_control.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/prime_core/telegram_control.py b/prime_core/telegram_control.py index 0c9dd37..1d7ca53 100644 --- a/prime_core/telegram_control.py +++ b/prime_core/telegram_control.py @@ -109,10 +109,30 @@ def run_prime(args: list[str]) -> tuple[int, str]: def _chat_answer(text: str) -> str: + import json prompt = f"You are Prime, Jason's assistant. Reply naturally and concisely. User message: {text}" code, out = run_prime(['dispatch','planning', prompt]) if code == 0 and out: - return out[:3000] + # out is JSON from prime dispatch; planning raw may be event stream lines + try: + obj = json.loads(out) + raw = str(obj.get('raw','')) + best = None + for line in raw.splitlines(): + line=line.strip() + if not line.startswith('{'): + continue + try: + ev = json.loads(line) + except Exception: + continue + item = ev.get('item') or {} + if item.get('type') == 'agent_message' and item.get('text'): + best = item.get('text') + if best: + return best[:1200] + except Exception: + pass return "Got it — I can help with that." def help_text() -> str: