Serena Dashboard and GUI
covers:
- src/serena/dashboard/**
- src/serena/gui_log_viewer.py
- src/serena/resources/dashboard/**
- src/serena/util/gui.py
- src/serena/util/pywebview.py
- src/serena/util/tray.py
Overview
Serena's dashboard is a local Flask-backed web UI served by src/…/dashboard_api.py and rendered from static files in src/serena/resources/dashboard/. SerenaDashboardAPI.run_in_thread() chooses the first free port at or above SerenaPorts.DASHBOARD_API_BASE_PORT, starts Flask in a daemon thread on the configured host, and serves /dashboard/ and /dashboard/<path> from SERENA_DASHBOARD_DIR. The same Flask app exposes JSON endpoints for live logs, tool usage, configuration state, memory editing, language-server management, task execution visibility/cancellation, remote news, and shutdown.
The API object is tied directly to the running SerenaAgent in src/…/dashboard_api.py. It registers _on_agent_config_changed() as a config-change callback and caches _current_config_overview so /get_config_overview can respond cheaply. That overview reads the active project, trust status, project root, languages, encoding, registered projects, active context/modes/tools, REPL facade availability, tool usage summaries, current client, Serena version, and any newer PyPI version. Mutating routes that touch project or global state either delegate to agent methods or run through the agent task executor: memory load/save/delete/rename uses project.memory_manager, language add/remove resolves through LanguageServerRegistry, global config edits read/write agent.serena_config.config_file_path, and save_web_dashboard_open_on_launch queues a config preference write.
The browser UI is defined by src/…/index.html, dashboard.js, and dashboard.css. index.html lays out an Overview page, Logs page, Advanced Stats page, modals for language/memory/global-config editing, and a shutdown action. dashboard.js owns the client-side state machine: it loads tool names first, initializes theme and banner rotation, switches pages, and starts/stops polling depending on the active page. The Overview page polls /get_config_overview, /queued_task_executions, and /last_execution once per second, while the Logs page polls /get_log_messages once per second using max_idx so only new log entries are appended after the initial full load. Advanced Stats requests /get_tool_stats and /get_token_count_estimator_name and renders charts through CDN-loaded Chart.js and chartjs-plugin-datalabels declared in index.html.
Logs come from a MemoryLogHandler passed into SerenaDashboardAPI in src/…/dashboard_api.py. /get_log_messages returns buffered messages plus the active project name; /clear_logs clears the in-memory buffer. The web dashboard escapes log text before inserting it (LogMessage.escapeHtml in dashboard.js), colors entries by DEBUG/INFO/WARNING/ERROR prefixes, and highlights known tool names. It also supports copying, saving, and clearing logs from the UI. A separate Tkinter fallback/viewer in src/…/gui_log_viewer.py can display the same memory log stream in a native window: GuiLogViewer drains a queue into a tk.Text widget, seeds itself from MemoryLogHandler.get_log_messages(), subscribes to new emits with add_emit_callback, highlights tool names, and in dashboard mode minimizes on close while exposing menu actions for shutdown and dashboard URL copy.
Native dashboard display is split between src/…/dashboard_viewer.py, src/…/pywebview.py, and src/…/dashboard_tray_manager.py. SerenaDashboardViewer is a small WebViewWithTray specialization that selects icons from src/serena/resources/dashboard/, uses oraios.serena as the Windows app id, and only advertises native viewer support on Windows and macOS. open_url_in_browser() optionally launches webbrowser.open() in a detached Python subprocess so opening a browser cannot write to stdout in stdio MCP contexts.
WebViewWithTray in src/…/pywebview.py wraps pywebview with optional pystray integration. It creates a hidden or visible webview window for the dashboard URL, intercepts window close when tray support is enabled so close hides rather than quits, and can monitor a parent Serena process id with psutil so the viewer exits when the agent process dies. On macOS it marshals show/hide through PyObjC helpers and switches the NSApplication activation policy between regular and accessory so a tray-minimized dashboard can disappear from the Dock; on Windows it sets the explicit app user model id before webview.start().
SerenaDashboardTrayManager in src/…/dashboard_tray_manager.py is a separate singleton-style process that aggregates all running dashboard instances behind one tray icon. ensure_running() probes http://127.0.0.1:<TRAY_MANAGER_PORT>/health, starts a detached Python process running SerenaDashboardTrayManager().run() if needed, and waits briefly for it to bind. The manager runs its own Flask app on the fixed tray-manager port with trusted hosts restricted to localhost and 127.0.0.1, accepts /register, /update_project, and /unregister calls from agent processes, and stores TrayManagedInstance records keyed by dashboard API port. The tray menu is generated dynamically from those records: a single instance becomes the default click action, multiple instances are sorted by start time and shown by project name/start timestamp. Opening a dashboard currently defaults to the system browser; if _use_pywebview is enabled, it spawns a child process running SerenaDashboardViewer(..., tray=False).
Threading is central to this area. SerenaDashboardAPI starts daemon threads for Flask, remote news fetch, and PyPI version checks; Flask itself runs threaded. The tray manager starts Flask and alive-check loops as daemon threads while pystray owns the UI loop. Because Flask request handlers and the alive-check thread can mutate tray UI state, SerenaDashboardTrayManager._run_in_ui_thread() calls PyObjCTools.AppHelper.callAfter() on macOS before updating the menu. GuiLogViewer.start() launches Tkinter in a daemon thread and uses a queue plus root.after() to keep widget updates on the Tk event loop. src/…/gui.py provides the simple display gate used by callers outside this doc: macOS and Windows are assumed usable, while Unix-like platforms require DISPLAY or WAYLAND_DISPLAY.
The static resource directory src/serena/resources/dashboard/ contains the HTML/CSS/JS and all dashboard/tray/log-viewer imagery: browser favicons (serena-icon-16.png, serena-icon-32.png, serena-icon-48.png), Windows app icon (serena.ico), macOS app icon (serena-icon-1024-mac.png), macOS tray template source (serena-icon-tray-mac.png), light/dark logos, log-viewer banner images, and vendored jquery.min.js. Remote network calls also exist in this UI path: dashboard.js loads sponsor/banner metadata from https://oraios-software.de/serena-banners/manifest.php, SerenaDashboardAPI._fetch_news() fetches https://oraios-software.de/serena_news.json with ETag caching under SerenaPaths, and _determine_newer_serena_version() queries PyPI for serena-agent.
Coupling
- If any response model or route shape in src/…/dashboard_api.py changes, update the matching AJAX consumers in src/…/dashboard.js; the client reads fields such as
active_project.name,tool_stats_summary,queued_executions,last_execution.logged,available_memories,jetbrains_mode, andnewer_serena_versiondirectly and usually reports failures only as generic UI errors. - If log buffering semantics change in src/…/logging.py or src/…/dashboard_api.py, verify both src/…/dashboard.js and src/…/gui_log_viewer.py: the web UI assumes monotonically increasing
max_idxand polls fromcurrentMaxIdx + 1, while the Tk viewer assumesMemoryLogHandler.add_emit_callback()can safely enqueue new formatted strings. - If task-executor task state changes, update
QueuedExecution.from_task_info()in src/…/dashboard_api.py and the execution rendering/cancellation code in src/…/dashboard.js; the UI hides unlogged executions and interpretsis_runningdifferently for cancellation confirmation versus queued cancellation. - If project memory naming rules change in the memory manager, update the regexes in src/…/dashboard.js for create/rename memory. The API in src/…/dashboard_api.py delegates to
project.memory_manager, but the browser blocks names before they reach the server. - If dashboard assets are renamed under
src/serena/resources/dashboard/, update every path embedded in src/…/dashboard_viewer.py, src/…/dashboard_tray_manager.py, src/…/gui_log_viewer.py, and src/…/index.html; these paths are constructed manually rather than discovered from a manifest. - If pystray is upgraded, verify src/…/tray.py.
create_tray_icon()subclassespystray.Iconon macOS and overrides the private_assert_image()implementation to produce a template NSImage, which is intentionally coupled to pystray internals. - If native viewer support is enabled on additional platforms in src/…/dashboard_viewer.py or src/…/dashboard_tray_manager.py, also verify src/…/gui.py display detection and src/…/pywebview.py tray/window behavior; imports of pystray, pywebview, PyObjC, and Tk are deliberately delayed or platform-gated because they can fail without a GUI display.
Risks
- src/…/dashboard_api.py exposes powerful local mutation endpoints, including
/save_serena_config,/save_memory,/delete_memory,/rename_memory,/add_language,/remove_language,/cancel_task_execution, and/shutdown. If the dashboard host or FlaskTRUSTED_HOSTSconfiguration is relaxed beyond loopback-safe use, a browser or local network caller could alter Serena state or terminate the server. - src/…/dashboard_api.py caches
_current_config_overviewand/get_config_overviewraises if the agent has not invoked the config-change callback yet. If the callback is not triggered during startup or after a failed config mutation, src/…/dashboard.js will keep showing generic configuration load errors while other dashboard pages may still work. - src/…/dashboard.js inserts remote news HTML returned by
/fetch_unread_newsinto the DOM by converting the HTML string with jQuery and appending it. If src/…/dashboard_api.py accepts compromised cached news fromSerenaPaths().news_fileor remote serena_news.json, the dashboard can render untrusted HTML in the local UI. - src/…/dashboard_tray_manager.py currently returns
Truefromis_current_platform_supported()even though comments say only Windows was tested and Linux support is still experimental. If callers assume the tray manager is production-supported everywhere, users on Linux/headless sessions may hit pystray/display failures despite src/…/gui.py being able to detect missing displays. - src/…/index.html loads Chart.js, chartjs-plugin-datalabels, Google Fonts, and remote banner content from CDNs/oraios hosts. In offline or restrictive environments, Advanced Stats charts, fonts, and banners may fail independently of the local Flask dashboard server.