File size: 5,899 Bytes
24214fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
"""
Cleanup script to remove test data from prompt management system.

This script removes any test indicators, templates, or rules that may have been
added during testing and restores the system to clean production state.
"""

import sys
import json
from pathlib import Path

def cleanup_indicators():
    """Remove test indicators from indicators.json."""
    indicators_file = Path("src/config/prompt_management/data/indicators.json")
    
    if not indicators_file.exists():
        print("❌ indicators.json not found")
        return False
    
    try:
        with open(indicators_file, 'r', encoding='utf-8') as f:
            data = json.load(f)
        
        original_count = len(data.get('indicators', []))
        
        # Remove test indicators
        clean_indicators = []
        for indicator in data.get('indicators', []):
            if isinstance(indicator, dict):
                name = indicator.get('name', '')
                # Skip test indicators
                if not any(test_pattern in name for test_pattern in [
                    'load_test_indicator',
                    'test_indicator',
                    'example_indicator'
                ]):
                    clean_indicators.append(indicator)
        
        data['indicators'] = clean_indicators
        
        with open(indicators_file, 'w', encoding='utf-8') as f:
            json.dump(data, f, indent=2, ensure_ascii=False)
        
        removed_count = original_count - len(clean_indicators)
        print(f"✅ Cleaned indicators: removed {removed_count} test indicators, kept {len(clean_indicators)} real ones")
        return True
        
    except Exception as e:
        print(f"❌ Error cleaning indicators: {e}")
        return False

def cleanup_templates():
    """Remove test templates from templates.json."""
    templates_file = Path("src/config/prompt_management/data/templates.json")
    
    if not templates_file.exists():
        print("❌ templates.json not found")
        return False
    
    try:
        with open(templates_file, 'r', encoding='utf-8') as f:
            data = json.load(f)
        
        original_count = len(data.get('templates', []))
        
        # Remove invalid/test templates
        clean_templates = []
        for template in data.get('templates', []):
            if isinstance(template, dict):
                template_id = template.get('template_id', '')
                name = template.get('name', '')
                content = template.get('content', '')
                
                # Skip test/invalid templates
                if (template_id and name and content and 
                    not any(test_pattern in template_id.lower() for test_pattern in [
                        'test', '000', 'example'
                    ]) and
                    not any(invalid_char in template_id for invalid_char in [
                        'ⳇ', 'ě', 's', 'Ś', 'ë', 'Ę', 'ė', 'Ą', 'ł', 'ij', 'Ť'
                    ]) and
                    len(content) > 10 and content != "0000000000"):
                    clean_templates.append(template)
        
        data['templates'] = clean_templates
        
        with open(templates_file, 'w', encoding='utf-8') as f:
            json.dump(data, f, indent=2, ensure_ascii=False)
        
        removed_count = original_count - len(clean_templates)
        print(f"✅ Cleaned templates: removed {removed_count} invalid templates, kept {len(clean_templates)} valid ones")
        return True
        
    except Exception as e:
        print(f"❌ Error cleaning templates: {e}")
        return False

def cleanup_rules():
    """Remove test rules from rules.json."""
    rules_file = Path("src/config/prompt_management/data/rules.json")
    
    if not rules_file.exists():
        print("❌ rules.json not found")
        return False
    
    try:
        with open(rules_file, 'r', encoding='utf-8') as f:
            data = json.load(f)
        
        original_count = len(data.get('rules', []))
        
        # Remove test rules
        clean_rules = []
        for rule in data.get('rules', []):
            if isinstance(rule, dict):
                rule_id = rule.get('rule_id', '')
                description = rule.get('description', '')
                
                # Skip test rules
                if (rule_id and description and 
                    not any(test_pattern in rule_id.lower() for test_pattern in [
                        'test', 'example', 'load_test'
                    ])):
                    clean_rules.append(rule)
        
        data['rules'] = clean_rules
        
        with open(rules_file, 'w', encoding='utf-8') as f:
            json.dump(data, f, indent=2, ensure_ascii=False)
        
        removed_count = original_count - len(clean_rules)
        print(f"✅ Cleaned rules: removed {removed_count} test rules, kept {len(clean_rules)} valid ones")
        return True
        
    except Exception as e:
        print(f"❌ Error cleaning rules: {e}")
        return False

def main():
    """Main cleanup function."""
    print("🧹 Cleaning up test data from prompt management system...")
    print("=" * 60)
    
    success = True
    
    # Cleanup each component
    success &= cleanup_indicators()
    success &= cleanup_templates()
    success &= cleanup_rules()
    
    print("=" * 60)
    
    if success:
        print("🎉 Cleanup completed successfully!")
        print("\n📋 Next steps:")
        print("  1. Restart the application to load clean data")
        print("  2. Check the Edit Prompts interface")
        print("  3. Verify prompts contain only relevant information")
    else:
        print("❌ Some cleanup operations failed. Check the errors above.")
        return 1
    
    return 0

if __name__ == "__main__":
    sys.exit(main())