Ershu Core
Ershu Core is the shared Python package used by the Ershu API, MCP server, and worker. It owns the data models, access rules, query primitives, run state, repository workspace safeguards, and database migrations that those services use in common.
This repository is for contributors working on shared backend behavior. It is not a standalone Ershu deployment: Core does not listen on a port, expose HTTP or MCP endpoints, or run repository analysis jobs. For a complete installation, start with the Ershu deployment repository.
Where Core fits
Frontend -> API ----+
|
AI client -> MCP ---+-> Core -> PostgreSQL / Milvus
|
Worker-+
API, MCP, and Worker depend on Core. They do not depend on one another.
| Area | What Core provides |
|---|---|
| Data and migrations | SQLAlchemy models, async sessions, Alembic revisions, and the ershu-db command |
| Projects and access | Projects, repositories, memberships, grants, user and project MCP key scopes, and visibility checks |
| Run state | Analysis runs, queue leases, events, blocks, conversations, cancellation, and retention |
| Documents and retrieval | Documents, sections, chunks, search selection, Milvus indexing, and reranking primitives |
| Project relationships | Shared queries for code indexes, knowledge graphs, change surfaces, and runtime flows |
| Repository access | Managed workspaces, trusted local path checks, Git URL restrictions, and read-only file access |
| Model channels | Shared records and selection rules for language, embedding, and reranking providers |
| Service contracts | Schemas, errors, identifiers, and runtime setting definitions shared across backend services |
Core does not contain FastAPI routes, browser authentication flows, MCP response formatting, worker analysis orchestration, LSP execution, or frontend code. Keep behavior used by only one service in that service's repository.
Repository layout
| Path | Contents |
|---|---|
src/ershu/core/ |
Configuration, logging, security checks, errors, and identifiers |
src/ershu/db/ |
Data models, async database sessions, and the migration command entry point |
src/ershu/schemas/ |
Data structures shared by backend services |
src/ershu/services/ |
Shared project, access, run, retrieval, repository, and model channel behavior |
src/ershu/tools/readonly_repository/ |
Path-constrained, read-only repository access |
alembic/ |
Database migration history |
tests/ |
Unit tests and optional checks against real services |
Install
Ershu Core requires Python 3.14. The
ershu installer package selects the Core
release pinned by that Ershu composition:
pip install ershu
Projects that depend on Core as a library can pin the component directly:
uv add "ershu-core==1.0.1.post20260812"
The API, MCP server, and Worker each declare the oldest Core release they
support. Their version numbers do not need to match Core. The ershu[api],
ershu[mcp], ershu[worker], and ershu[all] choices install a set of
component versions tested together.
After installation, confirm that the migration files are available:
uv run ershu-db heads
heads reads the packaged migration history without connecting to a database.
Configuration
Core reads environment variables and a .env file in the current working
directory. The repository's .env.example is a development
starting point:
cp .env.example .env
The main setting groups are:
| Group | Settings | Purpose |
|---|---|---|
| Process | APP_NAME, APP_VERSION, ENVIRONMENT, LOG_LEVEL |
Process identity and logging |
| PostgreSQL | DATABASE_URL, DATABASE_POOL_SIZE, DATABASE_MAX_OVERFLOW, DATABASE_POOL_TIMEOUT_SECONDS |
Persistent application and run data |
| Milvus | MILVUS_URI, MILVUS_TOKEN, MILVUS_DB_NAME |
Rebuildable vector indexes |
| Runs and search | RUN_QUEUE_LEASE_TIMEOUT_SECONDS, ANALYSIS_RUN_RETENTION_COUNT, SEARCH_INDEX_BATCH_SIZE |
Shared queue and indexing defaults |
| Sessions | SESSION_IDLE_TIMEOUT_MINUTES |
Shared session validation window |
| Repository access | REPOSITORY_STORAGE_PATH, TRUSTED_LOCAL_PATHS, GIT_ALLOWED_HOSTS, Git protocol switches |
Cache location and repository trust boundaries |
| Secrets | SECRET_KEY, ENCRYPTION_KEY, MCP_KEY_PEPPER |
Session signing, stored credential encryption, and MCP key verification |
| Repository credentials | GITHUB_TOKEN, GITLAB_TOKEN |
Fallback access when a repository has no stored credential |
validate_auth_secrets() rejects the configuration if a shared secret is
shorter than 32 characters, retains a known placeholder value, or duplicates
another secret. Generate three independent values before running a production
service.
Core accepts managed repository caches, Git checkouts, and paths explicitly
allowed by the caller. Use TRUSTED_LOCAL_PATHS for other local directories.
validate_common_runtime_settings() rejects
ALLOW_DEV_OPEN_LOCAL_REPOSITORY_PATHS=true when ENVIRONMENT is prod or
production.
Service-specific settings stay outside Core. Redis, browser tokens, cookies, CORS, and login settings belong to the API. Analysis concurrency, LSP images, and worker policies belong to Worker. MCP transport and DNS rebinding settings belong to the MCP server.
Database migrations
All Ershu backend services use the migration history shipped with Core. Back up the target database before an upgrade and run migrations with the Core version selected for that deployment.
Inspect the available migration head:
uv run ershu-db heads
Inspect the revision applied to the configured database:
uv run ershu-db current
Upgrade the database:
uv run ershu-db upgrade head
ershu-db current and ershu-db upgrade head use DATABASE_URL and connect to
the database. A successful heads command only confirms that the installed
package contains its migration files.
When changing a model:
- Update the model under
src/ershu/db/. - Add a revision under
alembic/versions/. - Test both upgrade and downgrade behavior. Do not rewrite a published revision.
- Build the package and check
ershu-db headsfrom the installed wheel.
Development
Clone the repository and install its locked development environment with UV:
git clone https://github.com/ershu-lab/ershu-core.git
cd ershu-core
uv sync --locked
Core can be installed, tested, and built without the API, MCP, Worker, or deployment repositories.
Run the checks used for regular changes:
uv run pytest -m "not integration"
uv run ruff check src tests
uv run ruff format --check src tests
uv build --no-sources
The default test command uses SQLite where a database is needed. The integration tests connect to real PostgreSQL and Milvus instances only when their test variables are set:
export ERSHU_TEST_POSTGRES_URL='postgresql+asyncpg://user:password@host:5432/ershu_test'
export ERSHU_TEST_MILVUS_URI='http://127.0.0.1:19530'
export ERSHU_TEST_MILVUS_TOKEN=''
export ERSHU_TEST_MILVUS_DB_NAME='default'
uv run pytest -m integration
Set only the services you intend to test. Keep real addresses and credentials in your local environment or secret store, not in the repository.
License
Ershu Core is licensed under the Apache License 2.0.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ershu_core-1.0.1.post20260812.tar.gz.
File metadata
- Download URL: ershu_core-1.0.1.post20260812.tar.gz
- Upload date:
- Size: 179.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fde9991624488bba99f4ad568929bcc72c82dd3cc5fd0b897f5bda9279a2be5
|
|
| MD5 |
edb97b37dbb3697b97f9c4365c6cad89
|
|
| BLAKE2b-256 |
7cb04a018eafb2f0942a6eef6b65111d003e773d74bda2b2d4117f57f8836e24
|
File details
Details for the file ershu_core-1.0.1.post20260812-py3-none-any.whl.
File metadata
- Download URL: ershu_core-1.0.1.post20260812-py3-none-any.whl
- Upload date:
- Size: 235.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e08e686d9efc147e27f2953ddd35eac0ea3abff37532397734ddae89642f7e0
|
|
| MD5 |
f3e955ab2af97d8cbd5577f5f757da14
|
|
| BLAKE2b-256 |
9265c14fe4ed2aa9ae943a2ce65d0a118e5ea053543edf812cfe375a109773d2
|