From 6bc0aa1f71b18201ad962f0b95102c904fe437d9 Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Fri, 10 Jul 2026 11:45:03 +0000 Subject: [PATCH] Sanitize MSR analysis prompt echo --- ltx_director.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/ltx_director.py b/ltx_director.py index acf1449..e06098a 100644 --- a/ltx_director.py +++ b/ltx_director.py @@ -512,6 +512,58 @@ def _analysis_text_is_usable(text: str) -> bool: return True +def _sanitize_analysis_text(text: str) -> str: + text = (text or "").strip() + if not text: + return "" + + if "" in text: + text = text.split("")[-1].strip() + + cleaned_lines = [] + for raw_line in text.splitlines(): + line = raw_line.strip().replace("**", "") + if not line: + continue + lower = line.lower() + if lower.startswith("the user wants"): + continue + if lower.startswith("key elements to include"): + continue + if lower.startswith("drafting the sentences"): + continue + if lower.startswith("sentence 1"): + continue + if lower.startswith("sentence 2"): + continue + if line.startswith("*"): + continue + if re.match(r"^\d+\.\s", line): + continue + cleaned_lines.append(line) + + text = " ".join(cleaned_lines).strip() + text = re.sub(r"\s+", " ", text) + if not text: + return "" + + sentences = re.split(r"(?<=[.!?])\s+", text) + descriptive = [] + for sentence in sentences: + sentence = sentence.strip() + if not sentence: + continue + lower = sentence.lower() + if "the user wants" in lower or "key elements" in lower or "drafting the sentences" in lower: + continue + descriptive.append(sentence) + + if descriptive: + return " ".join(descriptive[-2:]).strip() + + return text + + def _compress_analysis_image_b64(b64_payload: str, max_dim: int = 768, quality: int = 82) -> str: """Shrink analysis images so multimodal providers do not burn their full context on pixels.""" try: @@ -674,8 +726,7 @@ async def analyze_character_endpoint(request): "message": f"Could not connect to {provider} at {base_url}. Make sure the server is running and reachable.", }) - if "" in generated_text: - generated_text = generated_text.split("")[-1].strip() + generated_text = _sanitize_analysis_text(generated_text) log.info("[LTXDirector] Analysis complete: %s", generated_text) return web.json_response({"status": "success", "description": generated_text})