From 533f35cf61fa13c89375c41e6150b4fcbe20c026 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Tue, 27 May 2025 21:16:01 +0200 Subject: [PATCH] Allow to enable/disable the web dashboard in the configuration --- serena_config.template.yml | 19 +++++++++++++------ src/serena/agent.py | 26 ++++++++++++++------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/serena_config.template.yml b/serena_config.template.yml index 3c5500d1..f5a66f78 100644 --- a/serena_config.template.yml +++ b/serena_config.template.yml @@ -1,17 +1,24 @@ gui_log_window: False -# Whether to open a graphical window with Serena's logs (not supported on macOS). -# This is useful both for troubleshooting and for monitoring the tool calls, +# Whether to open a graphical window with Serena's logs. +# This is mainly supported on Windows and (partly) on Linux; not available on macOS. +# If you want to see the logs in a web browser, use the `web_dashboard` option instead. +# Limitations: doesn't seem to work with the community version of Claude Desktop for Linux +# Might also cause problems with some MCP clients - if you have any issues, try disabling this + +# Being able to inspect logs is useful both for troubleshooting and for monitoring the tool calls, # especially when using the agno playground, since the tool calls are not always shown, # and the input params are never shown in the agno UI. # When used as MCP server for Claude Desktop, the logs are primarily for troubleshooting. # Note: unfortunately, the various entities starting the Serena server or agent do so in # mysterious ways, often starting multiple instances of the process without shutting down -# previous instances. This leads to multiple log windows being opened, and only the last +# previous instances. This can lead to multiple log windows being opened, and only the last # window being updated. Since we can't control how agno or Claude Desktop start Serena, # we have to live with this limitation for now. -# -# Limitations: doesn't seem to work with the community version of Claude Desktop for Linux -# Might also cause problems with some MCP clients - if you have any issues, try disabling this + +web_dashboard: False +# Whether to open the Serena web dashboard (which will be accessible through your web browser) that +# shows Serena's current session logs - as an alternative to the GUI log window which +# is supported on all platforms. gui_log_level: 20 # minimum log level for the GUI log window (10 = debug, 20 = info, 30 = warning, 40 = error) diff --git a/src/serena/agent.py b/src/serena/agent.py index 957e3bc7..3320394b 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -206,6 +206,7 @@ class SerenaConfig: projects: list[Project] = field(default_factory=list) gui_log_window_enabled: bool = False gui_log_window_level: int = logging.INFO + web_dashboard: bool = True loaded_original_yaml: dict | CommentedMap = field(default_factory=dict) CONFIG_FILE = "serena_config.yml" @@ -262,6 +263,7 @@ class SerenaConfig: instance.gui_log_window_enabled = loaded_original_yaml.get("gui_log_window", False) instance.gui_log_window_level = loaded_original_yaml.get("gui_log_level", logging.INFO) + instance.web_dashboard = loaded_original_yaml.get("web_dashboard", True) instance.loaded_original_yaml = loaded_original_yaml # re-save the configuration file if any migrations were performed @@ -479,18 +481,23 @@ class SerenaAgent: if Logger.root.level > log_level: log.info(f"Root logger level is higher than GUI log level; changing the root logger level to {log_level}") Logger.root.setLevel(log_level) - self._gui_log_handler = GuiLogViewerHandler(GuiLogViewer(title="Serena Logs"), level=log_level, format_string=LOG_FORMAT) + self._gui_log_handler = GuiLogViewerHandler(GuiLogViewer("dashboard", title="Serena Logs"), level=log_level, format_string=LOG_FORMAT) Logger.root.addHandler(self._gui_log_handler) # instantiate all tool classes self._all_tools: dict[type[Tool], Tool] = {tool_class: tool_class(self) for tool_class in ToolRegistry.get_all_tool_classes()} - - # start the dashboard (web frontend) and register its log handler - memory_log_handler = MemoryLogHandler() - Logger.root.addHandler(memory_log_handler) tool_names = [tool.get_name() for tool in self._all_tools.values()] - self._dashboard_thread, port = SerenaDashboardAPI(memory_log_handler, tool_names).run_in_thread() - webbrowser.open(f"http://localhost:{port}/dashboard/index.html") + + # If GUI log window is enabled, set the tool names for highlighting + if self._gui_log_handler is not None: + self._gui_log_handler.log_viewer.set_tool_names(tool_names) + + # start the dashboard (web frontend), registering its log handler + if self.serena_config.web_dashboard: + dashboard_log_handler = MemoryLogHandler() + Logger.root.addHandler(dashboard_log_handler) + self._dashboard_thread, port = SerenaDashboardAPI(dashboard_log_handler, tool_names).run_in_thread() + webbrowser.open(f"http://localhost:{port}/dashboard/index.html") log.info(f"Starting Serena server (version={serena_version()}, process id={os.getpid()}, parent process id={os.getppid()})") log.info("Available projects: {}".format(", ".join(self.serena_config.project_names))) @@ -519,11 +526,6 @@ class SerenaAgent: self._active_tools: dict[type[Tool], Tool] = {} self._update_active_tools() - # If GUI log window is enabled, set the tool names for highlighting - if self._gui_log_handler is not None: - tool_names = [tool.get_name() for tool in self._active_tools.values()] - self._gui_log_handler.log_viewer.set_tool_names(tool_names) - # activate a project configuration (if provided or if there is only a single project available) if project is not None: self.activate_project_from_path_or_name(project)