In Python, I want you to use the latest type syntax (type | None) instead of Optional. I also want you to use a single space (=) around the equals sign (=) in function argument calls. It's important to use double quotation marks (") instead of single quotations ('). And finally, we want to always use trailing commas in multi-line function declarations and calls. There's never a reason to write unittest.main() manually, we have a script for running tests. Never use inline imports inside of functions (use file header even in tests), and always use from ... import ... syntax at the top of the file.
- For new code, avoid comments unless the logic is genuinely complex or the block is long
- When editing existing code, prefer updating comments over deleting them
- Comments should start with a lowercase letter, except in documentation or where grammar requires it
Never use generic ValueError, AssertionError, or bare Exception for raising errors. Always use the structured exceptions from util.errors (ValidationError, NotFoundError, AuthorizationError, ExternalServiceError, RateLimitError, ConfigurationError, InternalError). Each raise must include an error code from util.error_codes. When re-raising from a caught exception, always use raise ... from e to preserve the chain. When calling external services (LLMs, image APIs, web fetchers), always guard against empty/null/empty-array responses with ExternalServiceError.
- ALWAYS use
pipenvfor dependency management and Python command execution - ALL commands must be run from project root (where Pipfile exists)
- Never use
pipdirectly - always usepipenv installorpipenv run
- Ask the user to run
./tools/db_generate_migration -yto generate new Alembic migrations (auto-generates based on model changes) - Ask the user to run
./tools/db_apply_migrationto apply migrations to database (only with user's approval) - Always check if model imports in
src/db/alembic/env.pyare up to date before runningdb_generate_migration
- Use
pipenv install --devandpipenv run python src/main.py --devfor development server (includes hot reload, verbose logging, dev API key) - For code quality checks, run tools directly on changed Python files:
pipenv run ruff check --fix <files>andpipenv run python tools/check_spacing.py --fix <files> - For version bumps, run
./tools/bump_version {major|minor|patch}; major and minor bumps reset lower version segments, and the script updates both project config and API docs - Use
pipenv installandpipenv run python src/main.pyfor production runs - For all other operations like testing, always run inside of
pipenv
- Always run linting on changed Python files before commits:
pipenv run ruff check --fix <files>andpipenv run python tools/check_spacing.py --fix <files> - All scripts handle environment setup automatically (PYTHONPATH, .env files)
- All scripts are in
toolsdirectory and use commonmessagesfor colored output - Scripts validate project root location and fail safely if run from wrong directory
- You can see other rules in
.cursordirectory, if you need those rules - You can see the CI/CD pipeline in
.github/workflowsdirectory - You can see the API docs in
docs/directory (keep it updated!)