From cc8c6fd26860fdd73b3ce2d7952649dc29eb406c Mon Sep 17 00:00:00 2001 From: Claude Dev Date: Wed, 25 Mar 2026 01:38:37 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20Executive=20Summary=20Parser=20=E2=80=94?= =?UTF-8?q?=20akzeptiert=20JSON,=20Markdown=20und=20nummerierte=20Listen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/report_generator.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/report_generator.py b/src/report_generator.py index 8558f85..789a57c 100644 --- a/src/report_generator.py +++ b/src/report_generator.py @@ -150,10 +150,44 @@ LAGEBILD: try: result, usage = await call_claude(prompt, tools=None, model=CLAUDE_MODEL_FAST) - # In HTML-Liste umwandeln - lines = [line.strip().lstrip("- ").lstrip("* ") for line in result.strip().split("\n") if line.strip().startswith(("-", "*"))] + # Robuster Parser: Akzeptiert JSON, Markdown-Listen oder Freitext + lines = [] + text = result.strip() + + # Fall 1: JSON-Antwort (Haiku gibt manchmal JSON zurück) + if text.startswith("{"): + try: + data = json.loads(text) + for key in data: + if isinstance(data[key], list): + for item in data[key]: + clean = str(item).strip().lstrip("- ").lstrip("* ") + if clean: + lines.append(clean) + break + except json.JSONDecodeError: + pass + + # Fall 2: Markdown Bullet Points if not lines: - lines = [result.strip()] + for line in text.split("\n"): + stripped = line.strip() + if stripped.startswith(("- ", "* ")): + clean = stripped.lstrip("- ").lstrip("* ").strip() + if clean: + lines.append(clean) + + # Fall 3: Nummerierte Liste (1. 2. 3.) + if not lines: + for line in text.split("\n"): + m = re.match(r"^\d+\.\s+(.+)", line.strip()) + if m: + lines.append(m.group(1).strip()) + + # Fallback: Ganzen Text als einen Punkt + if not lines: + lines = [text[:500]] + html = "" return html except Exception as e: