# Contributing to AlphaAvatar

## Python 3.13 development environment

The development target is standard CPython 3.13, not a free-threaded interpreter.
`.python-version`, all package `requires-python` declarations, Ruff, mypy and CI use
that target. The root `pyproject.toml` owns workspace policy and development tools;
each distribution owns its runtime dependencies, entry points and packaged resources.
The shared `alphaavatar` namespace must not gain a root `__init__.py`.

### Migrate an existing Python 3.11 checkout

Stop the Host and wait for resource cleanup. Keep the working environment and workspace
backup; do not delete them to make a new installation succeed. Apply the source changes
in a separate worktree or checkout, then use a new virtual environment:

```bash
uv python install 3.13
uv lock --python 3.13
git diff -- uv.lock
UV_PROJECT_ENVIRONMENT=.venv313 uv sync --all-packages --locked --python 3.13
uv pip check --python .venv313/bin/python
.venv313/bin/alphaavatar --help
.venv313/bin/alphaavatar --version
```

Commit the resolver-generated lock together with the metadata after review. Never change
only the lock's Python header, use `--frozen` to accept a stale lock, or remove a failing
feature to claim the complete installation passed. Leave existing third-party pins in
place initially; update only a dependency with a demonstrated incompatibility, then
repeat resolution, installation and relevant feature checks. `uv sync --all-packages`
is the integration environment; a lint-only environment is deliberately not equivalent.

Run your chosen configuration with the new environment against your intended services.
Verify startup, a real dispatch and interaction, cancellation during startup and active
work, and normal shutdown before updating the service executable. Metadata, import and
wheel checks alone do not validate models, audio, tool effects, RTC or the AIRI browser.
Keep the old checkout/environment available for rollback; restoring code does not reverse
external tool effects or replace a workspace backup.

### Repeatable checks without loading models

Use the committed lock with uv 0.10.0 or newer. CI uses uv 0.10.0. Quality tools have their
own environment so checking code does not uninstall or replace runtime dependencies:

```bash
UV_PROJECT_ENVIRONMENT=.venv-quality uv sync --locked --only-group lint --no-install-workspace
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync python scripts/quality/check_workspace.py
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync ruff check .
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync ruff format --check .
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync pre-commit validate-config
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync python scripts/docs/check_docs.py
uv lock --check
```

`scripts/docs/check_docs.py` checks [docs/manifest.yaml](https://github.com/AlphaAvatar/AlphaAvatar/blob/21190a84b85a25f1bceabb49a7ebf5cbd8f4524f/docs/manifest.yaml), the relative links
and anchors of the documents it lists, and the [Roadmap](https://docs.alphaavatar.io/en/v0.7.0/roadmap.md)'s structure and its
two languages. List a new document in the manifest, or it fails.

Documentation pushed to `dev/v0.7.0` is published to the [docs site](https://docs.alphaavatar.io/en/v0.7.0):
the **Docs site** workflow runs this check, has the site built again and waits until it serves the
push. The site's [build.json](https://docs.alphaavatar.io/build.json) names the commit it serves;
retrying and adding a version are in the
[docs site repository](https://github.com/AlphaAvatar/AlphaAvatar-docs#publishing).

`scripts/quality/check_workspace.py` checks package metadata, dependency relationships,
entrypoint files, licenses and lock policy without importing the runtime. Its `--metadata-only` mode
is useful during authoring but explicitly skips source/lock validation; it is not a release
gate. `uv lock --check` is still required for resolver-level freshness. No command here
silently treats an unavailable tool or an empty test suite as a successful check.

Ruff is fixed at **0.12.9** in the dependency group, `required-version` and pre-commit.
Keep 100-column formatting and compact imports; trailing commas do not force expansion.
Unsafe fixes are not enabled. Inspect safe fixes and formatting before committing:

```bash
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync ruff check --fix .
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync ruff format .
git diff --check
git diff
```

The existing E501 and B904 exceptions are retained; do not add blanket F/I/B/UP exclusions
to conceal migration failures. Vendored `third_party` code, generated environments and
workspace data are excluded, but `.github` is not blanket-excluded. TID251 rejects static
`livekit.agents` imports; dependency/lock checks also reject the removed Agents SDK.
TC keeps imports for typing alone under `TYPE_CHECKING`, so far in the Host's package code
(`avatar-host/alphaavatar`) only; Pydantic reads its model fields' types at run time, so
their imports stay.
This is not a security analysis of dynamic import strings or arbitrary third-party code.

The repository's `/tests/` directory is currently local-only. Run maintained local tests
with the runtime environment when present; pytest exit code 5 means no tests were collected,
not a passing regression run. The quality workflow runs installation/import/build checks
but does not claim an absent committed test suite passed.

### Install local commit and push hooks

A committed `.pre-commit-config.yaml` does not install Git hooks. In each checkout, run:

```bash
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync pre-commit install \
  --hook-type pre-commit --hook-type pre-push
```

Commit hooks fix/check staged files. The read-only push hooks run Ruff lint and formatting
against the complete workspace, including when only configuration files changed. They do
not build distributions or call model services. CI remains authoritative: local hooks can
be bypassed and do not accompany commits to another machine.

After changing lint policy or Python syntax targets, align the complete baseline once:

```bash
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync ruff check --fix .
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync ruff format .
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync ruff check .
UV_PROJECT_ENVIRONMENT=.venv-quality uv run --no-sync ruff format --check .
git diff --check
git diff
```

Review PEP 695 type aliases and generic declarations explicitly; do not add `--unsafe-fixes`
to the hook. An unchanged file can pass unnoticed by a staged-file commit check while
failing the whole-tree CI check. When diagnosing hook installation, inspect
`git config --show-origin --get core.hooksPath` and the hook files in the effective hook
directory; no configured `core.hooksPath` is itself not an error.

### Build every distribution

Build tooling is separate from the runtime and lint environments:

```bash
UV_PROJECT_ENVIRONMENT=.venv-build uv sync --locked --only-group build --no-install-workspace
(
  set -e
  constraints="$(mktemp)"
  trap 'rm -f "$constraints"' EXIT
  uv export --locked --only-group build --no-emit-workspace --no-hashes \
    --output-file "$constraints" > /dev/null
  uv build --all-packages --no-sources --build-constraints "$constraints"
  UV_PROJECT_ENVIRONMENT=.venv-build uv run --no-sync twine check dist/*
)
```

The build group's Twine 7 and packaging 26.1-or-newer readers support Core Metadata 2.5.
Keep the metadata writer and readers compatible in the committed lock. Isolated builds
use constraints exported from that lock; installing a pinned Hatchling in `.venv-build`
alone does not constrain an isolated PEP 517 build. A successful wheel build does not
substitute for `twine check`. Do not edit artifact metadata or skip validation to make a
release pass.

Each distribution includes its own copy of the root Apache-2.0 `LICENSE`, README,
`pyproject.toml`, namespace source and existing package resources. License copies are
checked for drift. `--no-sources` verifies that building does not depend on uv's editable
workspace overrides; it does not prove that all runtime dependencies can be installed.
`uv build` builds each wheel from that package's sdist, so a package builds from what its
sdist holds alone, its version file included. Use a clean output directory when reviewing a
release's artifacts.

### Network and installation failures

Distinguish DNS errors, TCP connection failures, TLS verification failures and resolver
conflicts. A failed GitHub connection does not mean that a repository or dependency version
is missing. Use the environment's approved network/proxy configuration. Do not disable TLS
verification or write guessed IP addresses into permanent Git/DNS settings. A container
with no outbound connection cannot be repaired by changing a package constraint.

When working offline, use a previously populated uv cache or a controlled package mirror
with the required Python 3.13 artifacts. Do not replace the runtime installation result with
syntax checks. Record the failing command and stage without publishing proxy credentials,
access tokens or environment files.

## Plugin development

Plugin packages are grouped by responsibility:

| Layer | Package location | Responsibility |
| :--- | :--- | :--- |
| Foundation | `avatar-plugins/foundation/` | Shared service components used by other plugins. |
| Perception | `avatar-plugins/perception/` | User understanding, memory, identity, and interaction. |
| Tools | `avatar-plugins/tools/` | Research, document access, and external operations. |

Read [Plugin Layout and Boundaries](https://docs.alphaavatar.io/en/v0.7.0/plugins.md) before adding or moving a package.

Keep public namespaces under `alphaavatar.plugins.<plugin>`. Do not encode layer names into Python imports or YAML plugin selections. Keep processor-specific configuration, prompts, model specifications, and business logic with their owning processor.

Consumers own their tasks, streams, and request state; `FoundationRuntime` owns shared service components. Plugin registration must not initialize models. Select inference runners from the active configuration and resolve model files inside runner initialization.

Package changes must keep workspace membership, `[tool.uv.sources]`, dependency metadata, and `uv.lock` consistent; a new member's version file holds `VERSION`'s value ([Versions](#versions)). Review lockfile changes before committing, then verify:

```bash
uv lock --check
uv sync --all-packages --locked
```

Update the root plugin catalog with a concise capability description and accurate status. Existing plugins link to their README; planned plugins must not use placeholder links or imply that an implementation is available.

## Code conventions

Follow [Coding conventions](https://docs.alphaavatar.io/en/v0.7.0/development/coding-conventions.md): how modules and classes are ordered, and the names they use.

## Versions

`VERSION`, at the repository root, is AlphaAvatar's release version: the one version a
`vX.Y.Z` tag releases. What else carries it is derived from it and checked against it:

| Carried by | Where | How |
| --- | --- | --- |
| Each package (its component version) | `__version__` in its version file (`[tool.hatch.version] path`), which Hatchling writes into its wheel and sdist metadata | copied by `scripts/maintenance/version.py sync`; inside the package, so its sdist builds alone |
| The CLI | `alphaavatar --version`: `AlphaAvatar X.Y.Z`, the Host package's | the same copy; one line, which `install.sh` and installed Hosts' `upgrade` compare exactly |
| A Linux package build | `share/alphaavatar/manifest.json`, published beside the package too: `version`, the build ID `id` (`<version>-<commit, 12>`, then `-dirty.<UTC time>` for uncommitted changes), `commit`, `release` (the tag, or none), `archive`, every package's version | `packaging/linux/build.sh` reads `VERSION`, runs the check, and fails unless every package it built and holds carries it |
| A release | the `vX.Y.Z` tag | `v` + `VERSION`: `make release`, the Quality checks of a tag and `build.sh --release` refuse any other |

`alphaavatar doctor` (`packages.alphaavatar`) says the release its AlphaAvatar packages come
from, warns when they come from several, and names the package build it runs from.

Other numbers are not release versions, and change only with what they describe:

- **Protocol and format versions** change when that format changes incompatibly: the Host's
  process messages (`IPC_VERSION`), setup's plans and catalog (`FORMAT`), the Memory database
  (`SCHEMA_VERSION`), `docs/manifest.yaml`'s `schema`. Compatibility checks for plugin
  packages, provider integrations, configuration and runtime protocols are Roadmap RUN-22.
- **The documentation site** (AlphaAvatar-docs) names documentation versions such as
  `v0.7.0` after the release line they describe; its `build.json` names the exact commit of
  this repository each one was built from (the content snapshot) and `deployment`, Vercel's ID
  of the site's build. Neither is a release of AlphaAvatar.

Between releases `VERSION` keeps the last release's version; a build of a later commit is told
apart by its build ID. Release preparation sets the next version, and CI checks it:

```bash
uv run --no-sync python scripts/maintenance/version.py set 0.7.0   # VERSION, then every copy
uv run --no-sync python scripts/maintenance/version.py check       # --tag vX.Y.Z for a tag
```

`check` names each file whose copy differs from `VERSION` or is not in the form `sync`
writes: the file's one `__version__ = "X.Y.Z"` line, which is its only statement naming
`__version__` and the line Hatchling reads the package's version from (its default pattern's
first match), not an example in a string. It also names a `VERSION` that is not one `X.Y.Z`
line, and a `--tag` naming another version. `set` and `sync` check every copy before writing
any, so one they cannot write leaves every file as it was. The Quality workflow runs `check` on
every push, with the tag when the Release workflow calls it.

Edit `VERSION`, never a copy: `sync` writes `VERSION`'s value into each. The commit hook
`sync-version` ([installed with the others](#install-local-commit-and-push-hooks)) runs it on a
commit that changes `VERSION`, a version file or a `pyproject.toml`; when it writes a copy, the
commit stops so that you add what it wrote and commit again.

---

## 🧩 Release Process

A release is a GitHub Release carrying the Linux package. AlphaAvatar's Python packages
are not published to a package index; those published to PyPI before stay as they were.
Pushing a `vX.Y.Z` tag runs this pipeline:

```text
push v* tag
    ↓
Quality checks (lint, build, install)
    ↓                                    ↓
Linux package                            Generate Release Notes
  built in manylinux_2_28 for the tag,     docs/releases/vX.Y.Z.md
  installed and set up on a clean          + GitHub's PR changelog
  Ubuntu 24.04
    ↓                                    ↓
Create GitHub Release (after both)
  a draft with the notes → attach the package files → download them from the
  draft and check names, sizes and SHA-256s → publish
```

Quality refuses a tag other than `v` + `VERSION`, or packages that do not all carry
`VERSION`; the Linux package job builds only a tag that points at the commit being built. A
published Release keeps its files: a re-run changes nothing once it is public.

### 1. Prepare the release on `main`

Use CPython 3.13 and the committed lockfile. Ensure `main` is up-to-date and clean and
that the quality workflow passes. Set the version and prepare human-written notes before
pushing the tag:

```bash
git switch main
git pull --ff-only origin main
uv run --no-sync python scripts/maintenance/version.py set 0.7.0
make prepare-release
# Edit docs/releases/v0.7.0.md and update README.md as needed.
git add VERSION docs/releases/v0.7.0.md README.md
git add -u  # each package's version file
git commit -m "release: prepare v0.7.0"
make release
```

`make release` releases `VERSION`'s version: it checks that every package carries it and
that `v0.7.0` exists neither locally nor on `origin`, then pushes the branch and the tag;
GitHub Actions runs the quality, Linux package, notes, and Release stages shown above.
`make release` neither changes versions nor builds anything itself. Alternatively, push an
existing local `vX.Y.Z` tag after checking that it points to the intended source commit.
The workflow combines `docs/releases/vX.Y.Z.md` (if present) with GitHub's
configured PR changelog (`.github/release.yml`). Re-running the release job
will preserve an existing GitHub Release rather than overwrite its notes.

### 2. Verify the result

Verify that GitHub Actions completed the four release stages and that
`https://github.com/AlphaAvatar/AlphaAvatar/releases/tag/vX.Y.Z` contains
the expected manual and generated notes and the Linux package files
(`install.sh`, the package and its `.sha256`, the manifest, the wheels and
`SHA256SUMS`), and that the manifest's `version` and `release` name this release.

Changing `.github/workflows/release.yml` on `main` does not retroactively fix
old failed tag-triggered runs. A previously created GitHub Release remains in place.
