|
2 | 2 |
|
3 | 3 | ## Purpose |
4 | 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. |
| 5 | +This file is the auto-loaded entry point for AI agents working on the |
| 6 | +`commitizen` repository. It holds the rules an agent needs in **every** |
| 7 | +session. Deeper guidance lives in: |
7 | 8 |
|
8 | | -## Project Overview |
| 9 | +- [Contributing](docs/contributing/contributing.md) — setup, dev workflow, PR lifecycle. |
| 10 | +- [Contributing TL;DR](docs/contributing/contributing_tldr.md) — poe command cheat sheet. |
| 11 | +- [Pull Request Guidelines](docs/contributing/pull_request.md) — PR etiquette and AI-assisted policy. |
| 12 | +- [Architecture Overview](docs/contributing/architecture.md) — codebase topology and extension points. |
| 13 | +- [For AI Agents](docs/contributing/agents/index.md) — agent-shaped recipes, validation map, playbooks. |
9 | 14 |
|
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 | | -## Setup and Validation |
28 | | - |
29 | | -> Full contributor guidelines (prerequisites, workflow, PR process): [`docs/contributing/contributing.md`](docs/contributing/contributing.md). |
30 | | -
|
31 | | -### Bootstrap |
32 | | - |
33 | | -```bash |
34 | | -uv sync --frozen --group base --group test --group linters |
35 | | -uv run poe setup-pre-commit # install git hooks (uses prek, a pre-commit runner) |
36 | | -``` |
37 | | - |
38 | | -### Local commands |
| 15 | +Follow these instructions in addition to any higher-level tool or system rules. |
39 | 16 |
|
40 | | -- **Format**: `uv run poe format` (runs `ruff check --fix` then `ruff format`) |
41 | | -- **Lint**: `uv run poe lint` (runs `ruff check` then `mypy`) |
42 | | -- **Test**: `uv run poe test` (runs `pytest -n auto`) |
43 | | -- **CI-equivalent**: `uv run poe ci` (commit check + pre-commit hooks via `prek` + test with coverage) |
44 | | -- **Full local check**: `uv run poe all` (format + lint + check-commit + coverage) |
| 17 | +## Project at a glance |
45 | 18 |
|
46 | | -Always run at least `uv run ruff check --fix . && uv run ruff format .` before pushing. CI will fail if the formatter modifies any files. |
47 | | - |
48 | | -### CI pipeline |
49 | | - |
50 | | -- CI runs `poe ci` on a matrix of Python 3.10–3.14 × ubuntu/macos/windows. |
51 | | -- Pre-commit hooks are defined in `.pre-commit-config.yaml` and run via [`prek`](https://github.com/j178/prek) (a `pre-commit` compatible runner). |
52 | | -- The matrix is **fail-fast**: inspect the earliest failing job that completed; others are cancelled. |
53 | | - |
54 | | -### Common CI failure patterns |
55 | | - |
56 | | -- **"Format Python code...Failed"**: Run `uv run poe format` and commit the result. |
57 | | -- **mypy `[arg-type]` on TypedDict**: Dynamically-constructed dicts (e.g., from `pytest.mark.parametrize`) passed to TypedDict-typed params need `# type: ignore[arg-type]`. |
58 | | -- **"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. |
59 | | -- **`VersionProtocol` + `issubclass`**: This Protocol has non-method members (properties), so `issubclass()` raises `TypeError`. Use `hasattr` checks for runtime validation. |
| 19 | +- **Project**: `commitizen` — Python CLI for enforcing Conventional Commits, |
| 20 | + automating version bumps, and generating changelogs. |
| 21 | +- **Library + CLI**: code is reachable both via `cz` and `import commitizen`. |
| 22 | +- **Cross-platform**: tests run on Linux/macOS/Windows × Python 3.10–3.14. |
| 23 | + Avoid POSIX-only assumptions (paths, subprocesses, line endings). |
| 24 | +- **Key entrypoints**: |
| 25 | + - `commitizen/cli.py` — CLI definition (decli + argparse). |
| 26 | + - `commitizen/commands/` — one module per `cz` subcommand. |
| 27 | + - `commitizen/config/` — configuration discovery and parsing. |
| 28 | + - `commitizen/providers/` — version providers. |
| 29 | + - `commitizen/changelog_formats/` — changelog file formats. |
60 | 30 |
|
61 | | -## What to Read Before Changing |
| 31 | +## Read before changing |
62 | 32 |
|
63 | 33 | | Changing... | Read first | |
64 | 34 | |---|---| |
65 | 35 | | CLI flags/arguments | `commitizen/cli.py`, `docs/commands/<cmd>.md`, `tests/test_cli/` | |
66 | 36 | | Bump logic | `commitizen/bump.py`, `commitizen/commands/bump.py`, `docs/commands/bump.md` | |
67 | 37 | | Changelog generation | `commitizen/changelog.py`, `commitizen/changelog_formats/`, `docs/commands/changelog.md` | |
68 | 38 | | Version schemes | `commitizen/version_schemes.py`, `tests/test_version_schemes.py` | |
69 | | -| Version providers | `commitizen/providers/`, `tests/test_providers.py`, `docs/config/version_provider.md` | |
| 39 | +| Version providers | `commitizen/providers/`, `tests/providers/`, `docs/config/version_provider.md` | |
70 | 40 | | Config resolution | `commitizen/config/`, `tests/test_conf.py`, `docs/config/` | |
71 | 41 | | Tag handling | `commitizen/tags.py`, `tests/test_tags.py` | |
72 | 42 | | Pre-commit / CI | `.pre-commit-config.yaml`, `.github/workflows/`, `pyproject.toml` (poe tasks) | |
73 | 43 |
|
74 | | -## Coding Guidelines |
75 | | - |
76 | | -- **Types**: Preserve or improve existing type hints. |
77 | | -- **Errors**: Prefer `commitizen/exceptions.py` error types; keep messages clear for CLI users. |
78 | | -- **Output**: Use `commitizen/out.py`; do not add noisy logging. |
79 | | - |
80 | | -## When Unsure |
81 | | - |
82 | | -- Prefer **reading tests and documentation first** to understand the expected behavior. |
83 | | -- When behavior is ambiguous, **assume backward compatibility** with current tests and docs is required. |
| 44 | +For recurring task types (add a provider, deprecate an API, regenerate |
| 45 | +snapshots, ...), use the matching playbook in |
| 46 | +[For AI Agents § Playbooks](docs/contributing/agents/index.md#playbooks) |
| 47 | +instead of reinventing the workflow. |
| 48 | + |
| 49 | +## Do not touch |
| 50 | + |
| 51 | +These files are generated, tracked, or otherwise managed automatically. |
| 52 | +Do not edit them directly: |
| 53 | + |
| 54 | +- `CHANGELOG.md` — produced by `cz changelog`. Hand-edits will be |
| 55 | + overwritten on the next release. |
| 56 | +- `commitizen/__version__.py` — bumped by `cz bump` via the configured |
| 57 | + version provider. |
| 58 | +- `.pre-commit-config.yaml:rev:` lines under the `Commitizen` repo — |
| 59 | + bumped by `cz bump` (`version_files` in `pyproject.toml`). |
| 60 | +- `docs/images/cli_help/*.svg` and `docs/images/cli_interactive/*.gif` — |
| 61 | + regenerated by `uv run poe doc:screenshots`. See the |
| 62 | + [update-snapshots playbook](docs/contributing/agents/playbooks/update-snapshots.md). |
| 63 | +- `tests/**/*` snapshot files used by `pytest-regressions` — regenerated |
| 64 | + via `uv run poe test:regen`. |
| 65 | +- `uv.lock` — only modify by changing dependencies in `pyproject.toml` |
| 66 | + and running `uv sync`, never by hand-editing. |
| 67 | +- Anything under `__pycache__/`, `.mypy_cache/`, `.ruff_cache/`, `.venv/`, |
| 68 | + `site/`, `coverage.xml`, `junit.xml`. |
| 69 | + |
| 70 | +## Mandatory PR reminders |
| 71 | + |
| 72 | +These are easy to miss when working from an agent and are required by |
| 73 | +the PR template: |
| 74 | + |
| 75 | +1. **Complete the AI disclosure**. Check |
| 76 | + "Was generative AI tooling used to co-author this PR?" and fill in |
| 77 | + the `Generated-by:` trailer with the tool name. Details: |
| 78 | + [Pull Request Guidelines § AI-Assisted Contributions](docs/contributing/pull_request.md#ai-assisted-contributions). |
| 79 | +2. **Run `uv run poe all` before pushing**. This is the command named in |
| 80 | + the PR template; it auto-formats then runs the same lint/check/test |
| 81 | + pipeline as CI. To mirror CI exactly afterwards, run |
| 82 | + `uv run poe ci` (uses `prek`, does not auto-format). |
| 83 | +3. **Fill in "Steps to Test This Pull Request"** with the exact commands |
| 84 | + you ran locally — the maintainers re-run them. |
| 85 | +4. **Follow Conventional Commits** — the project uses itself to validate |
| 86 | + commit messages. |
| 87 | + |
| 88 | +## When unsure |
| 89 | + |
| 90 | +- Read the existing tests and user docs to understand the expected |
| 91 | + behavior before changing code. |
| 92 | +- When behavior is ambiguous, assume **backward compatibility with |
| 93 | + current tests and docs** is required. Add a deprecation window |
| 94 | + instead of breaking it; see the |
| 95 | + [deprecate-public-api playbook](docs/contributing/agents/playbooks/deprecate-public-api.md). |
| 96 | +- Cross-platform parity matters — if you cannot test on macOS or |
| 97 | + Windows locally, surface that in the PR description. |
0 commit comments