| 1 |
# AGENTS instructions |
| 2 |
|
| 3 |
## Purpose |
| 4 |
|
| 5 |
This file provides **project-specific guidance for AI agents** (and other automated tools) working on the `commitizen` repository. |
| 6 |
Follow these instructions in addition to any higher-level system or tool rules. |
| 7 |
|
| 8 |
## Project Overview |
| 9 |
|
| 10 |
- **Project**: `commitizen` - a tool to help enforce and automate conventional commits, version bumps, and changelog generation. |
| 11 |
- **Primary language**: Python (library + CLI). |
| 12 |
- **Cross-platform**: Tests run on Linux, macOS, and Windows. Avoid POSIX-only assumptions in code (paths, subprocesses, line endings). |
| 13 |
- **Key entrypoints**: |
| 14 |
- `commitizen/cli.py` - main CLI implementation. |
| 15 |
- `commitizen/commands/` - subcommands such as `bump`, `commit`, `changelog`, `check`, etc. |
| 16 |
- `commitizen/config/` - configuration discovery and loading. |
| 17 |
- `commitizen/providers/` - version providers (e.g., `pep621`, `poetry`, `npm`, `uv`). |
| 18 |
- **Config sources**: `pyproject.toml` (project config, poe tasks, ruff, mypy), `.pre-commit-config.yaml` (hooks), `.github/workflows/` (CI). |
| 19 |
|
| 20 |
## General Expectations |
| 21 |
|
| 22 |
- **Preserve public behavior and CLI UX** — no breaking changes to APIs, CLI flags, or exit codes unless explicitly requested. |
| 23 |
- **Update or add tests/docs** when you change user-facing behavior. |
| 24 |
- **Commit messages** must follow [Conventional Commits](https://www.conventionalcommits.org/) (enforced by commitizen itself). |
| 25 |
- **Pull requests** must follow the [Pull Request Guidelines](docs/contributing/pull_request.md) and the template in `.github/pull_request_template.md`. |
| 26 |
|
| 27 |
### Commit and Pull Request Types |
| 28 |
|
| 29 |
Choose the Conventional Commit type based on the change's release impact, not |
| 30 |
the files or subsystem it touches. The type controls automated version bumps: |
| 31 |
|
| 32 |
- `feat` triggers a minor release. |
| 33 |
- `fix`, `perf`, and `refactor` trigger a patch release. |
| 34 |
- `ci`, `docs`, `test`, `build`, and `chore` do not trigger a release. |
| 35 |
- A breaking-change marker triggers a major release. |
| 36 |
|
| 37 |
Use the same rule for pull request titles because squash merges use the title as |
| 38 |
the resulting commit message. In particular, use `ci:` for changes limited to |
| 39 |
workflows or release automation. A scope does not change release impact: |
| 40 |
`fix(ci): ...` still triggers a patch release. |
| 41 |
|
| 42 |
## Setup and Validation |
| 43 |
|
| 44 |
> Full contributor guidelines (prerequisites, workflow, PR process): [`docs/contributing/contributing.md`](docs/contributing/contributing.md). |
| 45 |
|
| 46 |
### Bootstrap |
| 47 |
|
| 48 |
```bash |
| 49 |
uv sync --frozen --group base --group test --group linters |
| 50 |
uv run poe setup-pre-commit # install git hooks (uses prek, a pre-commit runner) |
| 51 |
``` |
| 52 |
|
| 53 |
### Local commands |
| 54 |
|
| 55 |
- **Format**: `uv run poe format` (runs `ruff check --fix` then `ruff format`) |
| 56 |
- **Lint**: `uv run poe lint` (runs `ruff check` then `mypy`) |
| 57 |
- **Test**: `uv run poe test` (runs `pytest -n auto`) |
| 58 |
- **CI-equivalent**: `uv run poe ci` (commit check + pre-commit hooks via `prek` + test with coverage) |
| 59 |
- **Full local check**: `uv run poe all` (format + lint + check-commit + coverage) |
| 60 |
|
| 61 |
Always run at least `uv run ruff check --fix . && uv run ruff format .` before pushing. CI will fail if the formatter modifies any files. |
| 62 |
|
| 63 |
### CI pipeline |
| 64 |
|
| 65 |
- CI runs `poe ci` on a matrix of Python 3.10–3.14 × ubuntu/macos/windows. |
| 66 |
- Pre-commit hooks are defined in `.pre-commit-config.yaml` and run via [`prek`](https://github.com/j178/prek) (a `pre-commit` compatible runner). |
| 67 |
- The matrix is **fail-fast**: inspect the earliest failing job that completed; others are cancelled. |
| 68 |
|
| 69 |
### Common CI failure patterns |
| 70 |
|
| 71 |
- **"Format Python code...Failed"**: Run `uv run poe format` and commit the result. |
| 72 |
- **mypy `[arg-type]` on TypedDict**: Dynamically-constructed dicts (e.g., from `pytest.mark.parametrize`) passed to TypedDict-typed params need `# type: ignore[arg-type]`. |
| 73 |
- **"pathspec 'vX.Y.Z' did not match"**: `.pre-commit-config.yaml` pins a tag of this repo. Rebase onto master to pick up the tag. |
| 74 |
- **`VersionProtocol` + `issubclass`**: This Protocol has non-method members (properties), so `issubclass()` raises `TypeError`. Use `hasattr` checks for runtime validation. |
| 75 |
|
| 76 |
## What to Read Before Changing |
| 77 |
|
| 78 |
| Changing... | Read first | |
| 79 |
|---|---| |
| 80 |
| CLI flags/arguments | `commitizen/cli.py`, `docs/commands/<cmd>.md`, `tests/test_cli/` | |
| 81 |
| Bump logic | `commitizen/bump.py`, `commitizen/commands/bump.py`, `docs/commands/bump.md` | |
| 82 |
| Changelog generation | `commitizen/changelog.py`, `commitizen/changelog_formats/`, `docs/commands/changelog.md` | |
| 83 |
| Version schemes | `commitizen/version_schemes.py`, `tests/test_version_schemes.py` | |
| 84 |
| Version providers | `commitizen/providers/`, `tests/test_providers.py`, `docs/config/version_provider.md` | |
| 85 |
| Config resolution | `commitizen/config/`, `tests/test_conf.py`, `docs/config/` | |
| 86 |
| Tag handling | `commitizen/tags.py`, `tests/test_tags.py` | |
| 87 |
| Pre-commit / CI | `.pre-commit-config.yaml`, `.github/workflows/`, `pyproject.toml` (poe tasks) | |
| 88 |
|
| 89 |
## Coding Guidelines |
| 90 |
|
| 91 |
- **Types**: Preserve or improve existing type hints. |
| 92 |
- **Errors**: Prefer `commitizen/exceptions.py` error types; keep messages clear for CLI users. |
| 93 |
- **Output**: Use `commitizen/out.py`; do not add noisy logging. |
| 94 |
- **Testing**: Follow the Arrange, Act, Assert (AAA) pattern. Visually separate these phases with blank lines or comments. |
| 95 |
|
| 96 |
## When Unsure |
| 97 |
|
| 98 |
- Prefer **reading tests and documentation first** to understand the expected behavior. |
| 99 |
- When behavior is ambiguous, **assume backward compatibility** with current tests and docs is required. |
| 100 |
|
| 101 |
## Documentation Guidelines |
| 102 |
|
| 103 |
- 100% Coverage: Every new module, class, method, and function MUST have a docstring. No exceptions |
| 104 |
- Even simple functions or internal helpers require documentation to explain their context |
| 105 |
|
| 106 |
### Docstring Format: Modified Google Style |
| 107 |
|
| 108 |
Use Google Docstring Style with these major modifications: |
| 109 |
|
| 110 |
1. **NEVER include type hints in the docstring.** We rely exclusively on Python's PEP 484 type signatures. |
| 111 |
2. **Classes MUST include an example.** Any class documentation must contain a brief usage example formatted in Markdown. |
| 112 |
3. **Class Attributes MUST be documented.** The class docstring must document the instance variables initialized in `__init__` within an `Attributes:` section. |
| 113 |
|
| 114 |
**Format Rules:** |
| 115 |
|
| 116 |
- `Args:`, `Returns:`, and `Attributes:` sections must describe the _semantic meaning_ and _constraints_ of the variables, not their types. |
| 117 |
- Omit the type in the lists (e.g., use `user_id: The ID of the user`, NOT `user_id (int): The ID of the user`). |
| 118 |
|
| 119 |
### Content Focus: The "What" and "Why" |
| 120 |
|
| 121 |
Code explains _how_. Your docstrings must explain _what_ and _why_. |
| 122 |
|
| 123 |
When documenting, you may include: |
| 124 |
|
| 125 |
1. **The Core Intent** What business or technical rule is this solving? |
| 126 |
2. **Considerations:** Architectural choices. Why was this approach chosen over the obvious alternative? Why the complexity (if introduced)? |
| 127 |
3. **Discarded Approaches:** If a simpler method wasn't used (e.g., avoiding an ORM feature for raw SQL, or caching strategies), explain what was discarded and why. |
| 128 |
4. **Edge Cases & Gotchas:** What weird scenarios does this code handle? |
| 129 |
|
| 130 |
In the end, the reader must understand the intention behind the decisions, to avoid making the same mistakes. |