from textual.app import App from agentm.views.home import HomeView from agentm.views.login import LoginView from agentm import DIAMBRA_CREDENTIALS_PATH from agentm.utils.logger import log_with_caller from agentm.logic.db import initialize_database class AgentMApp(App): CSS_PATH = "assets/styles.tcss" def on_mount(self) -> None: """Called when the app starts.""" log_with_caller("debug", "App mounted. Initializing database...") initialize_database() log_with_caller("debug", "Checking for credentials...") if DIAMBRA_CREDENTIALS_PATH.exists(): token = DIAMBRA_CREDENTIALS_PATH.read_text().strip() if token and len(token) > 10: log_with_caller("info", "Found populated DIAMBRA credentials. Launching Home.") self.push_screen(HomeView()) return else: log_with_caller("warning", "Token file exists but appears empty or malformed.") log_with_caller("info", "No valid credentials found. Launching Login screen.") self.push_screen(LoginView()) async def on_login_view_login_success(self, message: LoginView.LoginSuccess) -> None: """Handle successful login event and switch to Home screen.""" log_with_caller("info", "Handling LoginSuccess event. Launching Home.") self.push_screen(HomeView())