Introducing a new way to review your PRs.

Read the announcement

oraios / serena

A powerful MCP toolkit for coding, providing semantic retrieval and editing capabilities - the IDE for your agent

View on GitHub

13 documents · Updated Nov 16, 2026

docs / repository-automation-and-utilities


slug: docs/repository-automation-and-utilities.md scope: Repository-level utilities, developer automation scripts, packaging/build metadata, and shared Serena utility helpers not owned by more specific modules. covers:

  • src/serena/util/**
  • repo_dir_sync.py
  • sync.py
  • scripts/add_spdx_headers.py
  • scripts/build_news_json.py
  • scripts/bump_version.py
  • scripts/live_test_grok.py
  • scripts/profile_search_text.py
  • scripts/profile_tool_call.py
  • pyproject.toml
  • flake.nix
  • flake.lock
  • compose.yaml
  • Dockerfile
  • docker_build_and_run.sh
  • docs/autogen_docs.py
  • docs/create_toc.py

Repository Automation and Utilities

Overview

This area collects the repository-level glue that supports Serena but is not itself a product flow: shared helpers in src/serena/util/**, release/build metadata in pyproject.toml, Nix/Docker packaging files, one-off developer scripts under scripts/, the repository-directory synchronizer, and documentation/news generators.

The shared utility modules are small but widely consumed by higher-level Serena modules:

  • File and text operations live in src/…/file_system.py, src/…/file_proxy.py, and src/…/text_utils.py. file_system.py provides atomic text writes with same-directory temp files, symlink-target preservation, Windows os.replace retry, recursive scans using os.scandir, .gitignore discovery/parsing, and pathspec matching fixes. file_proxy.py abstracts local project files and backend-provided external files behind FileProxy/FileCollection, with glob include/exclude filtering delegated to text_utils.GlobMatcher. text_utils.py implements regex search result rendering, brace-expanding glob matching, multi-file search, safe single-file and multi-file replacement previews/apply guards, HTML stripping, coordinate lookup, JSON output, and result-length limiting.
  • Configuration and persistence helpers live in src/…/yaml.py and src/…/dataclass.py. yaml.py wraps ruamel.yaml so Serena can load empty YAML as an empty CommentedMap, preserve/normalise comments, transfer comments between generated/default configs, and save YAML atomically with Windows rename retry. dataclass.py retrieves defaults and default factories from dataclass fields.
  • Process/runtime helpers live in src/…/shell.py, src/…/thread.py, src/…/logging.py, src/…/git.py, src/…/version.py, src/…/pypi.py, and src/…/dotnet.py. These cover subprocess execution, daemon-thread timeout wrapping, in-memory log buffering with callbacks, repository git-status detection, version-component comparisons, PyPI JSON API lookup, and .NET runtime discovery for language-server integrations.
  • UI/platform helpers live in src/…/gui.py, src/…/exception.py, src/…/tray.py, and src/…/pywebview.py. They detect usable/headless displays, safely log/show fatal exceptions, build platform-specific tray icons, and run a pywebview window with optional tray behavior and parent-process monitoring. macOS-specific code is isolated behind local imports and private pystray/NSApplication integration.
  • Reflection/CLI glue lives in src/…/inspection.py, src/…/cli_util.py, and src/…/class_decorators.py. These provide subclass iteration, language-server support composition over non-ignored files, yes/no prompts, auto-registering Click command groups, and a lightweight singleton decorator.

Packaging is centered on pyproject.toml. It declares the serena-agent package, Python support >=3.11,<3.15, exact runtime dependency pins, console entry points serena, serena-agent, and serena-hooks, optional extras, Hatch wheel package roots (src/serena, src/interprompt, src/solidlsp), ty/ruff/pytest/codespell configuration, and Poe tasks for tests, lint, type checks, and docs. The docs tasks call docs/autogen_docs.py, docs/create_toc.py, jupyter-book config sphinx docs/, and sphinx-build.

Nix packaging is defined by flake.nix and pinned in flake.lock. The flake uses nixpkgs, flake-utils, pyproject-nix, uv2nix, and pyproject-build-systems to load the uv workspace, build a Python 3.11 virtual environment, and expose a serena package/app. flake.nix includes package overrides for build-time setuptools needs, Linux GI bindings (pycairo, pygobject3) and pystray AppIndicator runtime metadata, plus a Linux wrapper that injects GApps/GI environment for the serena binary. Its dev shell pins UV_PYTHON_DOWNLOADS=never, points UV_PYTHON at the Nix Python, sets Linux LD_LIBRARY_PATH, and unsets PYTHONPATH.

Docker runtime support is in Dockerfile, compose.yaml, and docker_build_and_run.sh. The Docker image starts from python:3.11-slim, installs common developer tools, Node via nvm, uv, Rust/rust-analyzer, copies the repository into /workspaces/serena, creates a Serena config under SERENA_HOME=/workspaces/serena/config, disables GUI log/open-on-launch behavior while binding the web dashboard to 0.0.0.0, installs the editable package into a uv-created venv, and activates that venv through the entrypoint. compose.yaml builds the production target from Dockerfile, exposes MCP and dashboard ports on loopback using SERENA_PORT/SERENA_DASHBOARD_PORT, sets SERENA_DOCKER=1, and documents project mounts under /workspace/. docker_build_and_run.sh is a local convenience wrapper that builds serena and runs it interactively with the current directory mounted at /workspace.

Repository synchronization is implemented by repo_dir_sync.py and configured for this repo by sync.py. LibRepo represents the source library tree (sync.py sets name="serena", libDirectory="src"), and OtherRepo represents an external checkout (../serena-multiplexer/src-serena on branch mux). Push/pull operations copy whole directory trees between repositories, track sync points through .syncCommitId.remote and .syncCommitId.this, synthesize commit messages from git logs since the last sync, require interactive confirmation before destructive copies, and preserve configured ignored directories/files by backing up unversioned ignored paths and restoring versioned ignored paths with git checkout.

Developer automation scripts cover licensing, releases, news, profiling, live smoke tests, and documentation:

  • scripts/add_spdx_headers.py walks src/solidlsp, src/serena, src/interprompt, and scripts, inserting SPDX identifiers after shebang/encoding lines and module docstrings while skipping files that already contain an SPDX identifier or are empty.
  • scripts/bump_version.py is a Click CLI with release and dev commands. It requires a clean working tree via src/…/git.py, updates pyproject.toml and src/…/__init__.py, updates CHANGELOG.md and server.json for releases, runs uv lock, commits version changes, tags releases, and creates the next .dev0 commit.
  • scripts/build_news_json.py reads HTML snippets from SerenaPaths().news_dir, writes news/news.json, and can deploy it to Hades via scp when --deploy is passed and HADES_USER is set.
  • scripts/profile_search_text.py benchmarks old vs new line-coordinate resolution for search_text using synthetic content and asserts both implementations produce identical line ranges before timing.
  • scripts/profile_tool_call.py constructs a local SerenaAgent, waits for the language server, and profiles a FindSymbolTool.apply(name_path="DQN") call with either pyinstrument or cProfile.
  • scripts/live_test_grok.py is a zero-inference live test for the Grok Build integration. It resolves repository-local binaries, uses a private work directory, backs up and restores Grok config when not --hooks-only, runs targeted unit smoke tests, validates Grok context/tool exposure through stdio MCP probes, checks Serena hook JSON behavior, exercises serena setup grok, captures evidence files, and writes a Markdown report.
  • docs/autogen_docs.py generates docs from README sections and the runtime tool/facade registry, and can generate API RST files for Python packages. docs/create_toc.py shells out to jupyter-book toc from-project docs to regenerate docs/_toc.yml.

Coupling

  • If pyproject.toml changes project version syntax, package entry points, dependency pins, or Poe docs/test task names, also update scripts/bump_version.py and the docs/Nix/Docker paths that assume them. scripts/bump_version.py uses regexes against the [project] version field in pyproject.toml, rewrites src/…/__init__.py, runs uv lock, and commits all tracked changes with git add -u.
  • If Serena's global config template or dashboard defaults move, update Dockerfile: it copies src/…/serena_config.template.yml and edits gui_log_window, web_dashboard_listen_address, and web_dashboard_open_on_launch with sed during image build.
  • If dependency metadata around GUI/tray support changes in pyproject.toml, verify both flake.nix and Docker. flake.nix has explicit Linux overrides for pywebview/pystray support and wraps serena with GApps environment; Dockerfile installs Python package dependencies directly from pyproject.toml.
  • If .gitignore semantics, ignored-project filtering, or path glob behavior changes, check all consumers of src/…/file_system.py, src/…/file_proxy.py, and src/…/text_utils.py. GitignoreParser.should_ignore, FileCollection.filter_glob, search_files, and MultiFileReplacement._collect_files independently rely on POSIX-style normalized paths and the custom GlobMatcher brace expansion.
  • If YAML config generation/default handling changes, preserve src/…/yaml.py comment-normalisation behavior. It assumes top-level leading comments for transfer and strips nested comment associations; config-writing modules that round-trip user YAML depend on those comments surviving without corrupting empty or concurrently written files.
  • If Grok client setup, hook payloads, MCP protocol defaults, or context names change, update scripts/live_test_grok.py alongside the relevant client/setup docs and tests. The script hard-codes the grok context's excluded tools, expected symbolic project-mode tools, hook JSON shape, unit-test file list, and serena setup grok output fragments.
  • If docs structure or README headings change, update docs/autogen_docs.py. It extracts README content with a single regex spanning the opening <h3>, the ## Programming section boundary, and ## Features; mismatched headings make the generator assert rather than silently generate partial docs.
  • If the src library is moved or split, update sync.py and repo_dir_sync.py sync assumptions. The synchronizer copies whole trees and deletes the target tree before restoring ignored content, so wrong libDirectory/pathToLib values can remove unrelated files.

Risks

  • repo_dir_sync.py uses shutil.rmtree followed by shutil.copytree in both OtherRepo.pull and OtherRepo.push. If LibRepo.libDirectory, OtherRepo.pathToLibInThisRepo, or ignored-path restoration lists are wrong, the sync can delete the target tree or fail to restore local-only ignored content before committing.
  • scripts/bump_version.py performs real git operations (git add -u, git commit, git tag) and file rewrites after regex-based version extraction. If the regexes stop matching pyproject.toml, src/…/__init__.py, CHANGELOG.md, or server.json, releases can fail mid-flow after some files have already been updated.
  • src/…/tray.py overrides pystray's private macOS image path, and src/…/pywebview.py coordinates pystray with pywebview's NSApplication loop. If the pinned pystray==0.19.5 or pywebview==6.2 behavior changes in pyproject.toml, macOS tray/window behavior can break without type-level warning.
  • src/…/text_utils.py guards replacements through content-anchored occurrence ids and ambiguity checks, but MultiFileReplacement.apply asserts selected occurrence spans still match the scanned content. If a caller bypasses dry-run ids or applies stale selections after file content changes, replacement is rejected for that file rather than partially repaired.
  • Dockerfile exposes runtime behavior through shell activation in ENTRYPOINT and installs from pyproject.toml with uv pip install -r pyproject.toml -e .. If the executable used in compose.yaml diverges from installed console scripts, the container may build successfully but fail at startup.