Reduced Agent Debug Output and rewrote output.

This commit is contained in:
2025-09-02 21:39:44 -06:00
parent 4db6414da4
commit df1c41597e

View File

@@ -28,8 +28,24 @@ except Exception:
import aiohttp import aiohttp
import socketio import socketio
# Reduce noisy Qt output and attempt to avoid Windows OleInitialize warnings
os.environ.setdefault("QT_LOGGING_RULES", "qt.qpa.*=false;*.debug=false")
from qasync import QEventLoop from qasync import QEventLoop
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
try:
# Swallow Qt warnings like OleInitialize failures on Windows consoles
def _qt_msg_handler(mode, context, message):
# Intentionally suppress all Qt framework messages to keep console clean
return
QtCore.qInstallMessageHandler(_qt_msg_handler)
except Exception:
pass
try:
# Pre-initialize OLE to reduce chances of RPC_E_CHANGED_MODE warnings
import ctypes
ctypes.windll.ole32.OleInitialize(0)
except Exception:
pass
from PIL import ImageGrab from PIL import ImageGrab
# ////////////////////////////////////////////////////////////////////////// # //////////////////////////////////////////////////////////////////////////
@@ -52,9 +68,8 @@ class ConfigManager:
self.load() self.load()
def load(self): def load(self):
print("[DEBUG] Loading config from disk.")
if not os.path.exists(self.path): if not os.path.exists(self.path):
print("[DEBUG] Config file not found. Creating default.") print("[INFO] agent_settings.json not found - Creating...")
self.data = DEFAULT_CONFIG.copy() self.data = DEFAULT_CONFIG.copy()
self._write() self._write()
else: else:
@@ -62,7 +77,6 @@ class ConfigManager:
with open(self.path, 'r') as f: with open(self.path, 'r') as f:
loaded = json.load(f) loaded = json.load(f)
self.data = {**DEFAULT_CONFIG, **loaded} self.data = {**DEFAULT_CONFIG, **loaded}
print("[DEBUG] Config loaded:", self.data)
except Exception as e: except Exception as e:
print(f"[WARN] Failed to parse config: {e}") print(f"[WARN] Failed to parse config: {e}")
self.data = DEFAULT_CONFIG.copy() self.data = DEFAULT_CONFIG.copy()
@@ -75,7 +89,6 @@ class ConfigManager:
try: try:
with open(self.path, 'w') as f: with open(self.path, 'w') as f:
json.dump(self.data, f, indent=2) json.dump(self.data, f, indent=2)
print("[DEBUG] Config written to disk.")
except Exception as e: except Exception as e:
print(f"[ERROR] Could not write config: {e}") print(f"[ERROR] Could not write config: {e}")
@@ -83,7 +96,6 @@ class ConfigManager:
try: try:
mtime = os.path.getmtime(self.path) mtime = os.path.getmtime(self.path)
if self._last_mtime is None or mtime != self._last_mtime: if self._last_mtime is None or mtime != self._last_mtime:
print("[CONFIG] Detected config change, reloading.")
self.load() self.load()
return True return True
except Exception: except Exception:
@@ -100,7 +112,6 @@ def init_agent_id():
return CONFIG.data['agent_id'] return CONFIG.data['agent_id']
AGENT_ID = init_agent_id() AGENT_ID = init_agent_id()
print(f"[DEBUG] Using AGENT_ID: {AGENT_ID}")
def clear_regions_only(): def clear_regions_only():
CONFIG.data['regions'] = CONFIG.data.get('regions', {}) CONFIG.data['regions'] = CONFIG.data.get('regions', {})
@@ -645,7 +656,7 @@ async def send_agent_details():
@sio.event @sio.event
async def connect(): async def connect():
print(f"[WebSocket] Connected to Borealis Server with Agent ID: {AGENT_ID}") print(f"[INFO] Successfully Connected to Borealis Server!")
await sio.emit('connect_agent', {"agent_id": AGENT_ID}) await sio.emit('connect_agent', {"agent_id": AGENT_ID})
# Send an immediate heartbeat so the UI can populate instantly. # Send an immediate heartbeat so the UI can populate instantly.
@@ -978,18 +989,15 @@ async def macro_task(cfg):
# ---------------- Config Watcher ---------------- # ---------------- Config Watcher ----------------
async def config_watcher(): async def config_watcher():
print("[DEBUG] Starting config watcher")
while True: while True:
CONFIG.watch() CONFIG.watch()
await asyncio.sleep(CONFIG.data.get('config_file_watcher_interval',2)) await asyncio.sleep(CONFIG.data.get('config_file_watcher_interval',2))
# ---------------- Persistent Idle Task ---------------- # ---------------- Persistent Idle Task ----------------
async def idle_task(): async def idle_task():
print("[Agent] Entering idle state. Awaiting instructions...")
try: try:
while True: while True:
await asyncio.sleep(60) await asyncio.sleep(60)
print("[DEBUG] Idle task still alive.")
except asyncio.CancelledError: except asyncio.CancelledError:
print("[FATAL] Idle task was cancelled!") print("[FATAL] Idle task was cancelled!")
except Exception as e: except Exception as e:
@@ -1013,7 +1021,7 @@ async def connect_loop():
while True: while True:
try: try:
url=CONFIG.data.get('borealis_server_url',"http://localhost:5000") url=CONFIG.data.get('borealis_server_url',"http://localhost:5000")
print(f"[WebSocket] Connecting to {url}...") print(f"[INFO] Connecting Agent to {url}...")
await sio.connect(url,transports=['websocket']) await sio.connect(url,transports=['websocket'])
break break
except Exception as e: except Exception as e:
@@ -1024,7 +1032,6 @@ if __name__=='__main__':
app=QtWidgets.QApplication(sys.argv) app=QtWidgets.QApplication(sys.argv)
loop=QEventLoop(app); asyncio.set_event_loop(loop) loop=QEventLoop(app); asyncio.set_event_loop(loop)
dummy_window=PersistentWindow(); dummy_window.show() dummy_window=PersistentWindow(); dummy_window.show()
print("[DEBUG] Dummy window shown to prevent Qt exit")
try: try:
background_tasks.append(loop.create_task(config_watcher())) background_tasks.append(loop.create_task(config_watcher()))
background_tasks.append(loop.create_task(connect_loop())) background_tasks.append(loop.create_task(connect_loop()))