From cf9ad6c5fb7a724fc26d40486666c8588d119e3a Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Wed, 2 Jul 2025 23:48:29 +0200 Subject: [PATCH] Use ~/.serena/serena_config.yml as the only location for the config file, adding a migration for old files in the Serena directory --- README.md | 18 ++++++++++-------- src/serena/config/serena_config.py | 17 +++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 96220456..7517630f 100644 --- a/README.md +++ b/README.md @@ -201,11 +201,15 @@ This and other settings can be adjusted in the [configuration](#configuration) a git clone https://github.com/oraios/serena cd serena ``` -2. Optionally create a config file from the template and adjust it according to your preferences. - You can either place it in your user directory (`~/.serena/serena_config.yml`) or into - the Serena installation directory: +2. Optionally create the configuration file in your home directory, i.e. + + * `~/.serena/serena_config.yml` on Linux and macOS, or + * `%USERPROFILE%\.serena\serena_config.yml` on Windows. + + by copying the template and then adjusting it according to your needs: ```shell - cp src/serena/resources/serena_config.template.yml serena_config.yml + mkdir ~/.serena + cp src/serena/resources/serena_config.template.yml ~/.serena/serena_config.yml ``` If you just want the default config, you can skip this part, and a config file will be created when you first run Serena. 3. Run the server with `uv`: @@ -282,10 +286,8 @@ Run with parameter `--help` to get a list of available options. Serena's behavior (active tools and prompts as well as logging configuration, etc.) is configured in four places: 1. The `serena_config.yml` for general settings that apply to all clients and projects. - Serena will look for this file in your user directory under `.serena/serena_config.yml` - or within the Serena installation directory. - If you do not explicitly create the file, it will be auto-generated in the former location - when you first run Serena. + It is located in your user directory under `.serena/serena_config.yml`. + If you do not explicitly create the file, it will be auto-generated when you first run Serena. 2. In the arguments passed to the `serena-mcp-server` in your client's config (see below), which will apply to all sessions started by the respective client. In particular, the [context](#contexts) parameter should be set appropriately for Serena to be best adjusted to existing tools and capabilities of your client. diff --git a/src/serena/config/serena_config.py b/src/serena/config/serena_config.py index 522e283a..7c5ea64a 100644 --- a/src/serena/config/serena_config.py +++ b/src/serena/config/serena_config.py @@ -245,14 +245,15 @@ class SerenaConfig: if is_running_in_docker(): return os.path.join(REPO_ROOT, cls.CONFIG_FILE_DOCKER) else: - candidates = [ - str(Path.home() / SERENA_MANAGED_DIR_NAME / cls.CONFIG_FILE), - os.path.join(REPO_ROOT, cls.CONFIG_FILE), - ] - for candidate in candidates: - if os.path.exists(candidate): - return candidate - return candidates[0] + config_path = str(Path.home() / SERENA_MANAGED_DIR_NAME / cls.CONFIG_FILE) + + # migrate configuration in old location + old_config_path = os.path.join(REPO_ROOT, cls.CONFIG_FILE) + if os.path.exists(old_config_path): + log.info(f"Moving Serena configuration file from {old_config_path} to {config_path}") + shutil.move(old_config_path, config_path) + + return config_path @classmethod def from_config_file(cls, generate_if_missing: bool = True) -> "SerenaConfig":