mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-09-30 00:48:57 +01:00
The instructions file carried product documentation on add-ons, the update system and backups, general Python advice, a directory tree and code samples. Every agent session loaded all of it. Current guidance for agent instruction files is a short list of commands and project specific conventions the agent cannot infer from the code. Restructure the file into the pull request template rule, development commands, Python 3.14 syntax notes, testing rules, good practices and the AI policy. Drop the coverage threshold, which nothing in CI enforces. The file shrinks from about 2,700 to 1,100 tokens. Keep the Supervisor specific conventions: relative imports, per-module const.py, CoreSysAttributes with the sys_* properties, the executor for blocking calls, api_process with api_validate, exceptions from exceptions.py and plain test_ functions. Replace add-on with app throughout and state that add-on is the legacy term. The code has moved to app naming, so agents must use it in new code and keep addon only where an existing API field, config key or class name still carries it. Adopt the section layout and several rules from the AGENTS.md in Home Assistant Core that were not in the old file: the pointer to the VS Code tasks, the note on lazily evaluated annotations, the test rules on type annotations, usefixtures, branching and parametrization, and the rules on small try clauses and comments. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
4.8 KiB
4.8 KiB
GitHub Copilot & Claude Code Instructions
This repository contains the Home Assistant Supervisor, a Python 3 based container orchestration and management system for Home Assistant. It manages the Home Assistant Core, app and plugin containers through the Docker daemon and integrates with the host OS through D-Bus.
Pull Requests
- When opening a pull request, always use the description format from
.github/PULL_REQUEST_TEMPLATE.md.
Development Commands
- Install development dependencies with
pip install -r requirements.txt -r requirements_tests.txt. .vscode/tasks.jsoncontains useful commands used for development.- Lint and format with
ruff check --fix supervisor tests,ruff format supervisor testsandpylint supervisor. - Type check with
mypy --ignore-missing-imports supervisor/. - After finishing a code session, run
pre-commit run --all-filesto check for linting and formatting issues.
Python Syntax Notes
- Supervisor officially supports Python 3.14 as its minimum version. Do not flag syntax or features that require Python 3.14 as issues, and do not suggest workarounds for older Python versions.
- Python 3.14 explicitly allows
except TypeA, TypeB:without parentheses. Never flag this as an issue. - Python 3.14 evaluates annotations lazily (PEP 649). Forward references in annotations do not need to be quoted — annotations can reference names defined later in the module without quoting them or using
from __future__ import annotations. Do not flag unquoted forward references in annotations as issues.
Testing
- Use
pytest -qsx tests/to run tests, narrowing the path as needed. Tests mirror thesupervisor/module layout. - Write plain
test_functions with pytest fixtures. Do not addTest*classes, they are considered legacy style in this project. - Mock external dependencies (Docker, D-Bus, network calls). The fixtures in
tests/conftest.pyprovide a mockedCoreSys. - Ensure all test function parameters have type annotations.
- Prefer
@pytest.mark.usefixturesover arguments, if the argument is not going to be used. - Avoid using conditions/branching in tests. Instead, either split tests or adjust the test parametrization to cover all cases without branching.
- If multiple tests share most of their code, use
pytest.mark.parametrizeto merge them into a single parameterized test instead of duplicating the body. Usepytest.paramwith anidparameter to name the test cases clearly.
Good practices
- Apps are the containerized applications installed from stores. "Add-on" is the legacy term for the same thing. Use "app" in new code, comments and docs, and keep "addon" only where an existing API field, config key or class name still uses it.
- Use relative imports within the
supervisor/package (e.g.from ..docker.manager import ExecReturn), never absolutefrom supervisor...imports. - Use constants from
supervisor/const.pyinstead of hardcoding values. Module-specific constants go in a per-moduleconst.py(e.g.supervisor/store/const.py). - Classes that need system access inherit from
CoreSysAttributesand use theself.sys_*properties (sys_docker,sys_homeassistant,sys_host,sys_dbus,sys_bus,sys_config, ...). Access Docker throughself.sys_docker, never through the Docker SDK directly. - All I/O must be async. Run blocking calls through
self.sys_run_in_executor(). Put sync setup in__init__and async initialization inpost_init()orload(). - Raise the exceptions defined in
supervisor/exceptions.pyand chain them withfrom. Wrap D-Bus and Docker exceptions in Supervisor-specific ones. - API handlers use the
@api_processdecorator and validate input withapi_validate()fromsupervisor/api/utils.py. The decorator convertsAPIErrorandHassioErrorinto responses, so do not add manual error handling in handlers. - When catching exceptions, try-clauses should be as small as possible, i.e. avoid wrapping large blocks of code in a try-clause, and avoid catching exceptions from functions that are not expected to raise them.
- Keep comments concise. Prefer one short line stating the non-obvious constraint, or no comment at all.
- Do not add comments that just restate the code on the following line(s). Comments should only explain why (non-obvious constraints, surprising behavior, or workarounds), never what. Never add comments that justify a change by referencing what the code looked like before.
- Use American English for all code, comments, and documentation.
AI policy
This project follows the Open Home Foundation AI Policy. Autonomous contributions are not accepted: a human must review, understand, and be able to explain every change before it is submitted. Do not open issues or pull requests autonomously, and do not post comments on behalf of a user without their review.