-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (61 loc) · 2.57 KB
/
main.py
File metadata and controls
75 lines (61 loc) · 2.57 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
import subprocess
from pynput import keyboard
from langchain_core.messages import HumanMessage
# Import our tools and agent components
from agent import app
from schemas import TroubleshootingGuide
from tools import get_current_window_context
def show_notification(title, message):
"""Sends a desktop notification."""
try:
subprocess.run(['notify-send', title, message, '--urgency=critical'], check=True)
except Exception as e:
print(f"Failed to send notification: {e}")
def run_troubleshooter():
print("\n\033[94mHotkey Activated! Running Linux Troubleshooter...\033[0m")
# STEP 1: Get current app/window
active_window = get_current_window_context.invoke({})
print(f"--- Context Captured: '{active_window}' ---")
# STEP 2: Run agent deterministically with context
inputs = {
"messages": [HumanMessage(content=f"Analyze logs for '{active_window}'")],
"context": active_window
}
with open("/home/admin/Desktop/LinuxProject/debug.log", "a") as f:
f.write(f"\n--- Starting Troubleshooter for context '{active_window}' ---\n")
f.write(f"Inputs: {inputs}\n")
final_output = None
for output in app.stream(inputs, stream_mode="values"):
final_output = output['messages'][-1]
# STEP 3: Display results
if isinstance(final_output, TroubleshootingGuide):
title = f"💡 Error Found: {final_output.error_summary}"
message = (
f"<b>Context:</b> {active_window}\n"
f"<b>Cause:</b> {final_output.suspected_cause}\n"
f"<b>Log File:</b> {final_output.log_file_path or 'journalctl'}\n"
f"<b>Entry:</b> <code>{final_output.relevant_log_entry}</code>\n"
f"<b>Suggested Fix:</b> <code>{final_output.suggested_command or 'N/A'}</code>"
)
show_notification(title, message)
else:
text = getattr(final_output, "content", "No actionable logs found.")
show_notification("System Scan Complete", text)
# Hotkey: Space + M
HOTKEY = {keyboard.Key.space, keyboard.KeyCode.from_char('m')}
current_keys = set()
def on_press(key):
if key in HOTKEY:
current_keys.add(key)
if all(k in current_keys for k in HOTKEY):
run_troubleshooter()
def on_release(key):
try:
current_keys.remove(key)
except KeyError:
pass
if __name__ == "__main__":
print("Linux Troubleshooting Agent is active.")
print("Press Space + M to analyze recent system errors.")
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()