diff --git a/src/serena/agent.py b/src/serena/agent.py index 2d728610..8b198c5a 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -18,7 +18,7 @@ from interprompt.jinja_template import JinjaTemplate from serena import serena_version from serena.analytics import RegisteredTokenCountEstimator, ToolUsageStats from serena.config.context_mode import SerenaAgentContext, SerenaAgentMode -from serena.config.serena_config import SerenaConfig, ToolInclusionDefinition +from serena.config.serena_config import SerenaConfig, ToolInclusionDefinition, is_running_in_docker from serena.dashboard import SerenaDashboardAPI from serena.ls_manager import LanguageServerManager from serena.project import Project @@ -271,12 +271,13 @@ class SerenaAgent: if self.serena_config.web_dashboard: self._dashboard_thread, port = SerenaDashboardAPI( get_memory_log_handler(), tool_names, agent=self, tool_usage_stats=self._tool_usage_stats - ).run_in_thread(host=self.serena_config.web_dashboard_host) - host_for_url = self.serena_config.web_dashboard_host - # this usually means we are in docker, so we use localhost for URL (the user has to port-forward then) - if host_for_url == "0.0.0.0": - host_for_url = "127.0.0.1" - dashboard_url = f"http://{self.serena_config.web_dashboard_host}:{port}/dashboard/index.html" + ).run_in_thread(host=self.serena_config.web_dashboard_listen_address) + dashboard_listen_address = self.serena_config.web_dashboard_listen_address + if is_running_in_docker(): + # we use localhost for URL instead of the 0.0.0.0 that is configured for docker + # (the user has to port-forward then) + dashboard_listen_address = "127.0.0.1" + dashboard_url = f"http://{dashboard_listen_address}:{port}/dashboard/index.html" log.info("Serena web dashboard started at %s", dashboard_url) if self.serena_config.web_dashboard_open_on_launch: # open the dashboard URL in the default web browser (using a separate process to control diff --git a/src/serena/config/serena_config.py b/src/serena/config/serena_config.py index cfe3f0b1..6008f3d7 100644 --- a/src/serena/config/serena_config.py +++ b/src/serena/config/serena_config.py @@ -342,8 +342,8 @@ class SerenaConfig(ToolInclusionDefinition, ToStringMixin): trace_lsp_communication: bool = False web_dashboard: bool = True web_dashboard_open_on_launch: bool = True - web_dashboard_host: str = "127.0.0.1" - """Will be automatically set to '0.0.0.0' when running in Docker. Not loaded from config file.""" + web_dashboard_listen_address: str = "127.0.0.1" + """When running in Docker, this will be automatically set to '0.0.0.0' ignoring any configuration by the user.""" tool_timeout: float = DEFAULT_TOOL_TIMEOUT loaded_commented_yaml: CommentedMap | None = None config_file_path: str | None = None @@ -377,7 +377,7 @@ class SerenaConfig(ToolInclusionDefinition, ToStringMixin): def __post_init__(self) -> None: if is_running_in_docker(): - self.web_dashboard_host = "0.0.0.0" + self.web_dashboard_listen_address = "0.0.0.0" def _tostring_includes(self) -> list[str]: return ["config_file_path"] @@ -469,6 +469,8 @@ class SerenaConfig(ToolInclusionDefinition, ToStringMixin): instance.gui_log_window_enabled = False # not supported in Docker else: instance.gui_log_window_enabled = get_value_or_default("gui_log_window_enabled") + # in docker the post_init takes care of setting the address to 0.0.0.0, we ignore the user's setting + instance.web_dashboard_listen_address = get_value_or_default("web_dashboard_listen_address") instance.log_level = loaded_commented_yaml.get("log_level", loaded_commented_yaml.get("gui_log_level", logging.INFO)) instance.web_dashboard = get_value_or_default("web_dashboard") instance.web_dashboard_open_on_launch = get_value_or_default("web_dashboard_open_on_launch") diff --git a/src/serena/resources/serena_config.template.yml b/src/serena/resources/serena_config.template.yml index 6a6ae491..75aa5cff 100644 --- a/src/serena/resources/serena_config.template.yml +++ b/src/serena/resources/serena_config.template.yml @@ -20,12 +20,19 @@ web_dashboard: True # shows Serena's current session logs - as an alternative to the GUI log window which # is supported on all platforms. +web_dashboard_listen_address: 127.0.0.1 +# The address where the web dashboard will listen on (by default, localhost) +# Important: when running serena in docker, this configuration entry will be ignored and the +# address will be set to 0.0.0.0. (as it's running in a sandbox, this does not pose a safety issue) +# You can then port-forward it to a host of your choice, e.g., localhost + web_dashboard_open_on_launch: True # whether to open a browser window with the web dashboard when Serena starts (provided that web_dashboard # is enabled). If set to False, you can still open the dashboard manually by navigating to # http://localhost:24282/dashboard/ in your web browser (24282 = 0x5EDA, SErena DAshboard). # If you have multiple instances running, a higher port will be used; try port 24283, 24284, etc. + log_level: 20 # the minimum log level for the GUI log window and the dashboard (10 = debug, 20 = info, 30 = warning, 40 = error)