Skip to content

Commit fc76d1e

Browse files
committed
ai(rules[AGENTS]) Add AGENTS.md
1 parent 66e3f4f commit fc76d1e

File tree

1 file changed

+307
-0
lines changed

1 file changed

+307
-0
lines changed

AGENTS.md

Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to AI agents (including Claude Code, Cursor, and other LLM-powered tools) when working with code in this repository.
4+
5+
## CRITICAL REQUIREMENTS
6+
7+
### Test Success
8+
- ALL tests MUST pass for code to be considered complete and working
9+
- Never describe code as "working as expected" if there are ANY failing tests
10+
- Even if specific feature tests pass, failing tests elsewhere indicate broken functionality
11+
- Changes that break existing tests must be fixed before considering implementation complete
12+
- A successful implementation must pass linting, type checking, AND all existing tests
13+
14+
## Project Overview
15+
16+
gp-libs is a Python library providing internal utilities and extensions for git-pull projects. It focuses on extending Sphinx documentation and pytest functionality with support for docutils-compatible markup formats.
17+
18+
Key features:
19+
- **doctest_docutils**: Reimplementation of Python's doctest with support for reStructuredText and Markdown
20+
- **pytest_doctest_docutils**: pytest plugin for running doctests in documentation files
21+
- **linkify_issues**: Sphinx extension that converts issue references (e.g., `#123`) to hyperlinks
22+
- Supports testing doctest examples in `.rst` and `.md` files
23+
- Powers documentation testing across the git-pull ecosystem
24+
25+
## Development Environment
26+
27+
This project uses:
28+
- Python 3.10+
29+
- [uv](https://github.com/astral-sh/uv) for dependency management
30+
- [ruff](https://github.com/astral-sh/ruff) for linting and formatting
31+
- [mypy](https://github.com/python/mypy) for type checking
32+
- [pytest](https://docs.pytest.org/) for testing
33+
- [pytest-watcher](https://github.com/olzhasar/pytest-watcher) for continuous testing
34+
35+
## Common Commands
36+
37+
### Setting Up Environment
38+
39+
```bash
40+
# Install dependencies
41+
uv pip install --editable .
42+
uv pip sync
43+
44+
# Install with development dependencies
45+
uv pip install --editable . -G dev
46+
```
47+
48+
### Running Tests
49+
50+
```bash
51+
# Run all tests
52+
make test
53+
# or directly with pytest
54+
uv run pytest
55+
56+
# Run a single test file
57+
uv run pytest tests/test_doctest_docutils.py
58+
59+
# Run a specific test
60+
uv run pytest tests/test_doctest_docutils.py::test_function_name
61+
62+
# Run tests with test watcher
63+
make start
64+
# or
65+
uv run ptw .
66+
67+
# Run tests with doctests
68+
uv run ptw . --now --doctest-modules
69+
```
70+
71+
### Linting and Type Checking
72+
73+
```bash
74+
# Run ruff for linting
75+
make ruff
76+
# or directly
77+
uv run ruff check .
78+
79+
# Format code with ruff
80+
make ruff_format
81+
# or directly
82+
uv run ruff format .
83+
84+
# Run ruff linting with auto-fixes
85+
uv run ruff check . --fix --show-fixes
86+
87+
# Run mypy for type checking
88+
make mypy
89+
# or directly
90+
uv run mypy src tests
91+
92+
# Watch mode for linting (using entr)
93+
make watch_ruff
94+
make watch_mypy
95+
```
96+
97+
### Development Workflow
98+
99+
Follow this workflow for code changes (see `.cursor/rules/dev-loop.mdc`):
100+
101+
1. **Format First**: `uv run ruff format .`
102+
2. **Run Tests**: `uv run pytest`
103+
3. **Run Linting**: `uv run ruff check . --fix --show-fixes`
104+
4. **Check Types**: `uv run mypy`
105+
5. **Verify Tests Again**: `uv run pytest`
106+
107+
### Documentation
108+
109+
```bash
110+
# Build documentation
111+
make build_docs
112+
113+
# Start documentation server with auto-reload
114+
make start_docs
115+
116+
# Update documentation CSS/JS
117+
make design_docs
118+
```
119+
120+
## Code Architecture
121+
122+
gp-libs provides utilities for documentation testing and Sphinx extensions:
123+
124+
```
125+
src/
126+
├── doctest_docutils.py # Core doctest reimplementation
127+
├── pytest_doctest_docutils.py # pytest plugin
128+
├── linkify_issues.py # Sphinx extension
129+
├── docutils_compat.py # Compatibility layer
130+
└── gp_libs.py # Package metadata
131+
```
132+
133+
### Core Modules
134+
135+
1. **doctest_docutils** (`src/doctest_docutils.py`)
136+
- Reimplementation of Python's standard library `doctest` module
137+
- Supports docutils-compatible markup (reStructuredText and Markdown)
138+
- Handles `doctest_block`, `.. doctest::` directive, and ` ```{doctest} ` code blocks
139+
- PEP-440 version specifier support for conditional tests
140+
- Can be run directly: `python -m doctest_docutils README.md -v`
141+
142+
2. **pytest_doctest_docutils** (`src/pytest_doctest_docutils.py`)
143+
- pytest plugin integrating doctest_docutils with pytest
144+
- Collects and runs doctests from `.rst` and `.md` files
145+
- Full pytest fixture and conftest.py support
146+
- Registered as `pytest11` entry point
147+
148+
3. **linkify_issues** (`src/linkify_issues.py`)
149+
- Sphinx extension for automatic issue linking
150+
- Converts `#123` references to clickable hyperlinks
151+
- Configured via `issue_url_tpl` in Sphinx conf.py
152+
153+
4. **docutils_compat** (`src/docutils_compat.py`)
154+
- Compatibility layer for cross-version docutils support
155+
- Provides `findall()` abstraction for different docutils versions
156+
157+
5. **gp_libs** (`src/gp_libs.py`)
158+
- Package metadata (version, title, author, URLs)
159+
160+
## Testing Strategy
161+
162+
gp-libs uses pytest for testing with custom fixtures. The test suite includes:
163+
164+
- Unit tests for doctest parsing and execution
165+
- Integration tests for pytest plugin functionality
166+
- Sphinx app factory for testing extensions
167+
168+
### Test Structure
169+
170+
```
171+
tests/
172+
├── test_doctest_docutils.py # Tests for doctest module
173+
├── test_pytest_doctest_docutils.py # Tests for pytest plugin
174+
├── test_linkify_issues.py # Tests for linkify extension
175+
├── conftest.py # Fixtures and sphinx app factory
176+
└── regressions/ # Regression tests
177+
```
178+
179+
### Testing Guidelines
180+
181+
1. **Use existing fixtures over mocks** (see `.cursor/rules/dev-loop.mdc`)
182+
- Use fixtures from conftest.py instead of `monkeypatch` and `MagicMock` when available
183+
- Document in test docstrings why standard fixtures weren't used for exceptional cases
184+
185+
2. **Preferred pytest patterns**
186+
- Use `tmp_path` (pathlib.Path) fixture over Python's `tempfile`
187+
- Use `monkeypatch` fixture over `unittest.mock`
188+
189+
3. **Running tests continuously**
190+
- Use pytest-watcher during development: `uv run ptw .`
191+
- For doctests: `uv run ptw . --now --doctest-modules`
192+
193+
## Coding Standards
194+
195+
For detailed coding standards, refer to `.cursor/rules/dev-loop.mdc`. Key highlights:
196+
197+
### Imports
198+
199+
- **Use namespace imports**: `import enum` instead of `from enum import Enum`
200+
- **For typing**, use `import typing as t` and access via namespace: `t.NamedTuple`, etc.
201+
- **Use `from __future__ import annotations`** at the top of all Python files
202+
203+
### Docstrings
204+
205+
Follow NumPy docstring style for all functions and methods (see `.cursor/rules/dev-loop.mdc`):
206+
207+
```python
208+
"""Short description of the function or class.
209+
210+
Detailed description using reStructuredText format.
211+
212+
Parameters
213+
----------
214+
param1 : type
215+
Description of param1
216+
param2 : type
217+
Description of param2
218+
219+
Returns
220+
-------
221+
type
222+
Description of return value
223+
"""
224+
```
225+
226+
### Doctest Guidelines
227+
228+
1. **Use narrative descriptions** for test sections rather than inline comments
229+
2. **Move complex examples** to dedicated test files at `tests/examples/<path_to_module>/test_<example>.py`
230+
3. **Keep doctests simple and focused** on demonstrating usage
231+
4. **Add blank lines between test sections** for improved readability
232+
233+
### Git Commit Standards
234+
235+
See `.cursor/rules/git-commits.mdc` for detailed commit message standards.
236+
237+
Format commit messages as:
238+
```
239+
Component/File(commit-type[Subcomponent/method]): Concise description
240+
241+
why: Explanation of necessity or impact.
242+
what:
243+
- Specific technical changes made
244+
- Focused on a single topic
245+
```
246+
247+
Common commit types:
248+
- **feat**: New features or enhancements
249+
- **fix**: Bug fixes
250+
- **refactor**: Code restructuring without functional change
251+
- **docs**: Documentation updates
252+
- **chore**: Maintenance (dependencies, tooling, config)
253+
- **test**: Test-related updates
254+
- **style**: Code style and formatting
255+
- **py(deps)**: Dependencies
256+
- **py(deps[dev])**: Dev Dependencies
257+
- **ai(rules[LLM type])**: AI Rule Updates
258+
259+
Example:
260+
```
261+
doctest_docutils(feat[parse]): Add support for myst-parser code blocks
262+
263+
why: Enable doctest execution in Markdown documentation files
264+
what:
265+
- Add detection for ```{doctest} fence syntax
266+
- Register myst directives automatically
267+
- Add tests for Markdown doctest parsing
268+
```
269+
270+
## Debugging Tips
271+
272+
See `.cursor/rules/avoid-debug-loops.mdc` for detailed debugging guidance.
273+
274+
When stuck in debugging loops:
275+
276+
1. **Pause and acknowledge the loop**
277+
2. **Minimize to MVP**: Remove all debugging cruft and experimental code
278+
3. **Document the issue** comprehensively for a fresh approach
279+
4. **Format for portability** (using quadruple backticks)
280+
281+
## Sphinx/Docutils-Specific Considerations
282+
283+
### Directive Registration
284+
285+
- Use `_ensure_directives_registered()` to auto-register required directives
286+
- Supports myst-parser directives (`{doctest}`, `{tab}`)
287+
- Handles both reStructuredText and Markdown syntax
288+
289+
### Document Parsing
290+
291+
- Uses docutils for parsing `.rst` files
292+
- Uses myst-parser for parsing `.md` files
293+
- Both formats support doctest blocks
294+
295+
### linkify_issues Configuration
296+
297+
In your Sphinx `conf.py`:
298+
```python
299+
extensions = ["linkify_issues"]
300+
issue_url_tpl = 'https://github.com/git-pull/gp-libs/issues/{issue_id}'
301+
```
302+
303+
## References
304+
305+
- Documentation: https://gp-libs.git-pull.com/
306+
- GitHub: https://github.com/git-pull/gp-libs
307+
- PyPI: https://pypi.org/project/gp-libs/

0 commit comments

Comments
 (0)