#!/usr/bin/env python3 """ Test the phase marker formatting fixes """ import re def filter_internal_tags(text): """Apply the same filtering logic as the main app""" # Remove internal tags text = re.sub(r'', '', text, flags=re.IGNORECASE) text = re.sub(r'', '', text) # Fix phase formatting - ensure consistent formatting phase_patterns = [ # Fix incorrect formats (missing asterisks) first (r'(? 1: issues.append(f"❌ '{marker}' appears {count} times (should be 1)") print("Issues found:") for issue in issues: print(f" {issue}") print("\n### After applying filters:") print("-" * 40) # Apply filtering filtered = filter_internal_tags(problematic_text) # Check if issues are fixed print("\nFiltered text (first 500 chars):") print(filtered[:500]) print("...") print("\n### Verification:") print("-" * 40) # Verify each phase marker is correctly formatted correct_markers = [ "**🎯 PLANNING:**", "**🔧 EXECUTING:**", "**🤔 REFLECTING:**", "**✅ SYNTHESIS:**" ] for marker in correct_markers: count = filtered.count(marker) if count == 1: print(f"✅ {marker} appears exactly once") # Check if on its own line marker_pos = filtered.find(marker) if marker_pos > 0: # Check character before char_before = filtered[marker_pos - 1] if char_before == '\n': print(f" ✅ On its own line") else: print(f" ❌ Not on its own line (preceded by: {repr(char_before)})") elif count == 0: print(f"⚪ {marker} not found") else: print(f"❌ {marker} appears {count} times") # Check for incorrect formats incorrect_formats = ["🤔 REFLECTING:", "🎯 PLANNING:", "🔧 EXECUTING:", "✅ SYNTHESIS:"] for wrong in incorrect_formats: if wrong in filtered and f"**{wrong}**" not in filtered: print(f"❌ Still contains incorrect format: {wrong}") print("\n" + "=" * 70) print("SUMMARY") print("=" * 70) print(""" The filtering patterns have been enhanced to: 1. Fix missing asterisks (🤔 REFLECTING: → **🤔 REFLECTING:**) 2. Ensure markers appear on new lines (add \\n\\n before) 3. Add spacing after markers 4. Clean up excessive whitespace The system prompt has also been updated to: 1. Explicitly require asterisks for bold formatting 2. Emphasize markers must be on new lines 3. Clarify each phase should appear EXACTLY ONCE 4. Show examples of correct vs incorrect formats """)