This repository uses AGENTS.md to guide AI/automation and humans on how to make safe, high‑quality changes quickly. Everything here applies to the entire repo.
- Keep public behavior stable unless explicitly requested. Avoid breaking changes.
- Prefer minimal, surgical diffs that fix the root cause.
- All linters, type checks, tests, and docs doctests must pass.
- Do not leak secrets. Redact sensitive data in logs and examples.
- Document non‑obvious code with concise, helpful docstrings.
- Language: Python 3.10+
- Package:
polla_app– alternative‑source ingestion for Chilean Loto (pozos only) - CLI entry:
python -m polla_appwith commands:run,publish,pozos,health - Tests:
pytest -q(unit, integration, doctests) - Style: Black, Ruff (including pep8‑naming), Mypy (strict-ish)
- Observability: structured JSON logs with correlation IDs, spans, and metrics
- Contracts: artifacts/results include
api_version(seepolla_app/contracts.py)
- SOLID
- Single Responsibility: keep modules/functions focused on one concern. Split large functions into helpers.
- Open/Closed: prefer additive changes (new helpers/flags/fields). Avoid breaking existing behavior/outputs.
- Liskov Substitution: maintain type contracts; don’t narrow accepted types or return shapes.
- Interface Segregation: use small, specific functions; avoid leaking cross‑cutting concerns in signatures.
- Dependency Inversion: depend on abstractions (e.g.,
Mapping,Iterable, protocols) and inject IO via parameters.
- DRY: eliminate duplication (regexes, network helpers, version constants). Reuse shared utilities and fixtures.
- KISS: choose the simplest approach that solves the problem; avoid new deps and over‑engineering.
- Zen of Python: explicit over implicit; readability counts; simple > complex; flat > nested.
- PEP‑8: enforced by Ruff + Black. Naming:
snake_casefor functions/vars,CapWordsfor classes,UPPER_SNAKEfor constants. Keep imports sorted; write meaningful docstrings.
- OK: bug fixes, test additions, small refactors that preserve behavior, performance improvements that keep outputs the same, docs changes.
- ASK FIRST: adding new dependencies, changing CLI flags or outputs, network‑heavy features, schema or API changes (see Contracts).
- DO NOT: commit secrets, hardcode credentials, add flakey/online tests, remove existing public flags or keys without a migration.
- Package version single‑source:
polla_app/__init__.py: __version__.pyproject.tomlreads it dynamically ([tool.setuptools.dynamic]). Don’t add another version constant.
- Artifact/result API version:
polla_app/contracts.py: API_VERSION.- If you add fields: keep them additive and update tests & docs. If you must remove/rename, bump
API_VERSIONand provide migration notes.
- If you add fields: keep them additive and update tests & docs. If you must remove/rename, bump
- Deprecations: keep backward‑compat aliases for at least one MINOR version (e.g.,
_normalise_*→_normalize_*).
Note: Keep this file named AGENTS.md. The automation reads AGENTS.md automatically; renaming to another filename (e.g., AGENTS_AI.md) may cause it to be ignored.
- Inputs via env vars (don’t hardcode):
GOOGLE_SPREADSHEET_ID(required for publish, not for dry‑run)- Credentials:
service_account.jsonfile ORGOOGLE_SERVICE_ACCOUNT_JSONORGOOGLE_CREDENTIALS/CREDENTIALS ALT_SOURCE_URLS(JSON mapping for source overrides)POLLA_USER_AGENT(override HTTP UA)POLLA_RATE_LIMIT_RPS(optional per‑host rate limit)
- Use
polla_app.obs:set_correlation_idand correlation propagation is handled by the pipeline logger.span(name, log, attrs=...)around meaningful phases.metric(name, log, kind=..., value=..., tags=...)for counters/gauges.sanitize(...)is applied before writing logs; don’t bypass unless necessary.
- Logs must be structured JSON; avoid logging secrets or large payloads.
- Use the taxonomy in
polla_app/exceptions.py:ConfigErrorfor missing/invalid configRobotsDisallowedErrorfor robots.txt denials (subclasses PermissionError)ScriptErrorbase provideserror_code,context,log_error()
- Error messages should be actionable and safe (no secret values).
- DRY: prefer shared helpers (e.g.,
_fetch_pozos) and precompiled regexes. - Respect robots.txt and env UA override.
- Never add network calls to tests; stub or provide fixtures.
run: pozos‑only ingestion; preserves state; emits artifacts and JSON logs.publish: dry‑run by default in tests; requires spreadsheet + credentials to write.pozos: prints current estimates.health: offline/online health checks with structured output.- Add new commands only if they are testable and documented.
- Run locally:
ruff check .black .mypy polla_app testspytest -q- Doctests for docs:
pytest --doctest-glob='*.md' README.md docs -q
- CI workflows:
tests.yml: Ruff, Black (check), Mypy, Pytestdocs.yml: doctests (installs package withpip install -e .)health.yml: daily offline health
- Tests must be deterministic; use fixtures and monkeypatching for IO/HTTP.
- Keep functions small and single‑purpose; write docstrings for non‑obvious logic.
- Use typing everywhere (Mapping/Iterable for read‑only params).
- Names: snake_case for functions/vars; CapWords for classes; avoid abbreviations.
- Do not introduce global mutable state except via controlled caches (e.g., rate limiter). Guard with tests.
- Propose change, indicating:
- Affected artifacts/fields
- Backward compatibility strategy
- API version impact (
API_VERSIONbump only if breaking)
- Add/extend tests in
tests/test_contracts.pyto lock new schema. - Update docs in
docs/VERSIONING.mdand README if user‑visible. - Ship with additive fields wherever possible.
- All CI checks green (tests, docs doctests, health offline)
- Bump
polla_app.__version__and add CHANGELOG entry - Verify artifacts include correct
api_version - Sanity check
health --onlinein a safe environment
- Avoid unnecessary network or parsing work.
- Reuse precompiled regexes and cached robots.txt parsers.
- Use opt‑in
POLLA_RATE_LIMIT_RPSto be a good citizen when sources are polled frequently.
- Never log tokens or credentials; rely on redaction.
- Treat environment values as sensitive unless documented otherwise.
- Do not add telemetry that sends data to third parties.
- Keep README concise with runnable snippets.
- Update
docs/API.md,docs/SLOs.md, anddocs/VERSIONING.mdwhen changing APIs, reliability SLOs, or contracts. - Prefer doctest‑style examples for small code snippets.
Following this guide ensures consistent, safe updates that respect user trust, testing, and operations. If a change requires bending these rules, document the exception and rationale in the PR description and the code.