File size: 1,745 Bytes
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
4552666
 
 
63bcd5a
4552666
 
 
 
 
 
 
 
 
 
63bcd5a
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
4552666
63bcd5a
 
 
4552666
63bcd5a
 
 
 
 
 
4552666
63bcd5a
 
 
 
 
 
4552666
63bcd5a
 
 
4552666
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
import re

def is_command(text: str) -> bool:
    """
    Detect if input is a system/terminal command
    """

    if not text:
        return False

    text = text.strip().lower()

    
    
    
    if text in {"exit", "quit", "clear"}:
        return True

    
    
    
    command_patterns = [
        r"^python\s+\S+\.py",          
        r"^pip\s+install",            
        r"^npm\s+install",            
        r"^node\s+\S+",               
        r"^cd\s+.+",                  
        r"^ls\b",                     
        r"^dir\b",                    
        r"^git\s+.+",                 
        r"^sudo\s+.+",                
        r".+\.py\s*$",                
    ]

    for pattern in command_patterns:
        if re.match(pattern, text):
            return True

    
    
    
    if "run" in text and re.search(r"\.py\b", text):
        return True

    return False

def handle_command(text: str) -> str:
    """
    Return safe response for command-like inputs
    """

    text = text.lower().strip()

    
    if text in {"exit", "quit"}:
        return "👋 Session ended. Start a new chat anytime."

    
    if re.search(r"python\s+\S+\.py", text):
        return (
            "⚠️ This looks like a code execution command.\n"
            "I only help with graduation project ideas and development."
        )

    
    if "pip install" in text or "npm install" in text:
        return (
            "⚠️ Installation commands are outside my scope.\n"
            "I can help you design your graduation project instead."
        )

    
    return (
        "⚠️ This looks like a system command.\n"
        "Please ask about graduation projects (ideas, features, or system design)."
    )