-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutilities.py
More file actions
101 lines (85 loc) · 3.88 KB
/
Copy pathutilities.py
File metadata and controls
101 lines (85 loc) · 3.88 KB
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
import os
import subprocess
import webbrowser
import logging
import psutil
# --- Jarvis Cognitive Modules ---
from modules.code_intelligence import CodeIntelligence
from modules.vision_module import JarvisVision
from modules.memory_module import TemporalMemory
from modules.cloud_brain import CloudBrain
from modules.agentic_executor import AgenticExecutor
from modules.system_monitor import ProactiveMonitor
# --- System Initialization ---
try:
code_intel = CodeIntelligence()
vision = JarvisVision()
journal = TemporalMemory()
llm = CloudBrain()
executor = AgenticExecutor(llm_engine=llm)
# Initialize the monitor globally here so we can control it via voice
monitor = ProactiveMonitor()
logging.info("All Jarvis cognitive modules initialized successfully.")
except Exception as e:
logging.error(f"Critical Engine Initialization Error: {e}")
def _evaluate_intent(command: str) -> str:
# Get the structured JSON dictionary from the Cloud Brain
intent_data = llm.analyze_intent(command)
intent = intent_data.get("intent", "CONVERSATION")
target = intent_data.get("target", "")
action = intent_data.get("action", "")
logging.info(f"Structured Intent: {intent_data}")
# 1. HANDLE SYSTEM ALERTS ("Ignore CPU spikes")
if intent == "SYSTEM_CONTROL":
if "mute" in action or "ignore" in command:
monitor.snooze(minutes=30)
return "Understood. I have muted hardware telemetry alerts for the next 30 minutes."
return "System parameters acknowledged."
# 2. HANDLE WEB NAVIGATION
elif intent == "WEB_SEARCH":
if "youtube" in action.lower() or "youtube" in command:
if target and target.lower() != "youtube":
webbrowser.open(f"https://www.youtube.com/results?search_query={target}")
return f"Pulling up {target} on YouTube."
else:
webbrowser.open("https://www.youtube.com")
return "Opening YouTube now."
else:
if target:
webbrowser.open(f"https://www.google.com/search?q={target}")
return f"Searching the web for {target}."
else:
webbrowser.open("https://www.google.com")
return "Opening Google."
# 3. HANDLE LOCAL APPS WITH FAIL-SAFE
elif intent == "OPEN_APP":
if not target: return "Which application would you like me to open?"
try:
subprocess.Popen(f"start {target}", shell=True)
return f"Attempting to launch {target}."
except Exception:
# The Fail-Safe: If it crashes, search google instead.
logging.warning(f"Could not find local app {target}. Falling back to web.")
webbrowser.open(f"https://www.google.com/search?q={target}")
return f"I couldn't locate {target} installed on this system, so I am searching the web for it instead."
# 4. VISION & DEBUGGING
elif intent == "VISION_DEBUG":
screen_text = vision.read_screen_text()
if "error" in screen_text.lower() or "traceback" in screen_text.lower():
results = code_intel.semantic_search(screen_text[:300])
if results:
return f"I see the error on your screen. It traces back to this local file:\n{results[0][:300]}..."
return f"I am scanning the screen. I see text related to: {screen_text[:100]}..."
# 5. GENERAL CHAT
elif intent == "CONVERSATION":
return llm.generate_chat_response(command)
return "System Error: Routing protocol failed."
def process_command(command: str) -> str:
clean_command = command.lower().strip()
response = _evaluate_intent(clean_command)
try:
if 'journal' in globals():
journal.log_interaction(clean_command, response)
except Exception as e:
logging.error(f"Memory journal write failed: {e}")
return response