File size: 3,130 Bytes
fea1bd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
HASHIRU 6.1 - Simple Fix Script
Corrige problemas criticos sem caracteres especiais
"""
import time
from pathlib import Path


def main():
    print("HASHIRU 6.1 - Simple Fixes")
    print("=" * 30)
    
    main_file = Path("main_agent.py")
    if not main_file.exists():
        print("ERROR: main_agent.py not found!")
        return
    
    try:
        # Read with UTF-8
        print("Reading main_agent.py...")
        content = main_file.read_text(encoding='utf-8')
        original_content = content
        fixes = 0
        
        # Fix 1: Duplicate Optional
        if "Optional, Optional" in content:
            content = content.replace(
                "from typing import Dict, List, Any, Optional, Optional",
                "from typing import Dict, List, Any, Optional"
            )
            print("  Fixed: Duplicate Optional import")
            fixes += 1
        
        # Fix 2: HTTP client bug
        if "httpx.AsyncClient()# Engine" in content:
            content = content.replace(
                "httpx.AsyncClient()# Engine de auto-modificação (opcional)",
                "httpx.AsyncClient()\n        \n        # Engine de auto-modificacao"
            )
            print("  Fixed: HTTP client concatenation")
            fixes += 1
        
        # Fix 3: Replace emojis that cause encoding issues
        emoji_replacements = [
            ("🔧", "[FIX]"),
            ("✅", "[OK]"),
            ("⚠️", "[WARN]"),
            ("🚨", "[ERROR]"),
            ("🎯", "[TARGET]"),
            ("🔥", "[HOT]"),
            ("⚡", "[FAST]"),
            ("💥", "[CRASH]"),
            ("🤖", "[BOT]"),
            ("▶️", "->"),
        ]
        
        for emoji, replacement in emoji_replacements:
            if emoji in content:
                content = content.replace(emoji, replacement)
                fixes += 1
        
        if fixes > 0:
            print("  Replaced emojis with ASCII")
        
        # Save if changes made
        if fixes > 0:
            # Backup
            backup_file = Path(f"main_agent_backup_{int(time.time())}.py")
            backup_file.write_text(original_content, encoding='utf-8')
            print(f"  Backup: {backup_file}")
            
            # Save fixed
            main_file.write_text(content, encoding='utf-8')
            print(f"  Applied {fixes} fixes")
        else:
            print("  No fixes needed")
        
        # Test import
        print("Testing import...")
        import subprocess
        result = subprocess.run([
            "python", "-c", "import main_agent; print('SUCCESS')"
        ], capture_output=True, text=True, encoding='utf-8')
        
        if result.returncode == 0 and "SUCCESS" in result.stdout:
            print("  Import test: PASSED")
            print("\nStatus: READY!")
            print("Run: chainlit run main_agent.py --port 8080")
        else:
            print(f"  Import test: FAILED")
            print(f"  Error: {result.stderr}")
        
    except Exception as e:
        print(f"ERROR: {e}")


if __name__ == "__main__":
    main()