Imported from fraud-platform/card-fraud-rule-management (
AGENTS.md). Install upstream withnpx skills add fraud-platform/card-fraud-rule-management. Copyright stays with the author.
AGENTS.md
This is the canonical instruction file for all coding agents working in this repository (Codex, Claude, Cursor, Copilot, etc.).
If another instruction file conflicts with this one, follow AGENTS.md.
Cross-Repo Agent Standards
- Secrets: Doppler-only workflows. Do not create or commit
.envfiles. - Commands: use repository wrappers from
pyproject.tomlorpackage.json; avoid ad-hoc commands. - Git hooks: run
git config core.hooksPath .githooksafter clone to enable pre-push guards. - Git workflow: work only on local
main; do not create branches or linked worktrees. Push onlyorigin/main. The pre-push guard covers Codex and Claude sessions; agents requireCARD_FRAUD_ALLOW_GIT_PUSH=1for an explicitly requested push. - Docs publishing: keep only curated docs in
docs/01-setupthroughdocs/07-reference, plusdocs/README.mdanddocs/codemap.md. - Docs naming: use lowercase kebab-case for docs files. Exceptions:
README.md,codemap.md, and generated contract files. - Never commit docs/planning artifacts named
todo,status,archive, or session notes. - If behavior, routes, scripts, ports, or setup steps change, update
README.md,AGENTS.md,docs/README.md, anddocs/codemap.mdin the same change. - Keep health endpoint references consistent with current service contracts (for APIs, prefer
/api/v1/health). - Preserve shared local port conventions from
card-fraud-platformunless an explicit migration is planned. - Before handoff, run the repo's local lint/type/test gate and report the exact command + result.
1) Critical Rule: Doppler Is Mandatory
- Never use
.envfiles in this project. - Never run
uv run testoruv run devdirectly. - Always use Doppler wrapper commands.
Required wrappers:
- Dev server:
uv run doppler-local - Tests (local DB):
uv run doppler-local-test - Tests (Neon test):
uv run doppler-test - Tests (Neon prod branch):
uv run doppler-prod
2) Quickstart Commands
# Install dependencies
uv sync --extra dev
# Local full setup (DB + object storage + bootstrap)
uv run local-full-setup --yes
# Run API (with Doppler local secrets)
uv run doppler-local
# Run tests (Doppler wrappers only)
uv run doppler-local-test
uv run doppler-test
uv run doppler-prod
# Lint / format
uv run lint
uv run format
# Regenerate OpenAPI
uv run openapi
3) Database + Infra Commands
# Local Postgres
uv run db-local-up
uv run db-local-down
uv run db-local-reset
# Local MinIO (S3-compatible)
uv run objstore-local-up
uv run objstore-local-down
uv run objstore-local-reset
uv run objstore-local-verify
# Start/stop both DB + object store
uv run infra-local-up
uv run infra-local-down
# Schema/setup commands
uv run db-init
uv run db-init-test
uv run db-init-prod
uv run db-verify
uv run db-verify-test
uv run db-verify-prod
uv run db-reset-data
uv run db-reset-tables
uv run db-reset-schema --yes --schema-reset-ack RESET_SHARED_SCHEMA
uv run db-seed-demo
# Neon automation
uv run neon-setup --yes --create-compute
uv run neon-full-setup --yes
uv run db-sync-doppler-urls --yes
4) Auth0 Commands
# Idempotent bootstrap / verify / cleanup
uv run auth0-bootstrap --yes --verbose
uv run auth0-verify
uv run auth0-cleanup --yes --verbose
Auth0 reference docs:
docs/07-reference/auth-model.mddocs/01-setup/auth0-setup-guide.md
Auth0 audience ownership:
AUTH0_AUDIENCEis the service audience for this backend.AUTH0_USER_AUDIENCEis the shared human-user audience used by the portal and role namespace.AUTH0_TEST_CLIENT_IDandAUTH0_TEST_CLIENT_SECRETbelong only to the confidentialLocal Test Clientused by local role-specific test helpers; keep both in Doppler.- The
/test-user-tokenhelper uses the canonical role users and caches one password-realm token per role in the running process. Do not add a password-grant request inside each test or load-test task. - Keep Suspicious IP Throttling and Brute-force Protection enabled; allowlist the current local egress IP when necessary for a development tenant.
uv run auth0-bootstrap --yes --verbosealso deploys the shared credentials-exchange Action that mirrors issued M2M access-token scopes intopermissions.
5) Project Truths (Do Not Violate)
- IDs are UUIDv7 and generated in application code.
- Postgres schema is
fraud_gov. - Driver is asyncpg (async) + psycopg v3 (sync), never psycopg2.
- Compiler output must be deterministic (same input => same bytes).
- Maker-checker invariant: maker cannot approve own submission.
- Authorization is permission-based (
require_permission(...)). - Prometheus
GET /metricsaccepts the legacyX-Metrics-Tokenheader and standardAuthorization: Bearer <METRICS_TOKEN>; both use constant-time comparison. - HTTP metrics route labels must use route templates (never raw request paths).
PLATFORM_ADMINmust retain a defense-in-depth allow-all bypass in backend permission checks.- The auth boundary returns typed
AuthenticatedUserobjects, not raw JWT dicts.
Rule type -> evaluation mode mapping:
ALLOWLIST->FIRST_MATCHBLOCKLIST->FIRST_MATCHAUTH->FIRST_MATCHMONITORING->ALL_MATCHING
6) Repository Layout
- API app:
app/ - CLI entry points:
cli/ - DB DDL and SQL:
db/ - Utility scripts:
scripts/ - Tests:
tests/ - Documentation:
docs/
7) Documentation Policy
When code changes, update docs in the same PR.
Minimum docs to check/update:
README.mddocs/README.mddocs/03-api/reference.md(or regeneratedocs/03-api/openapi.jsonwhen API/schema changes)
8) Testing Policy
Use Doppler wrappers only.
Recommended flow before merge:
uv run doppler-local-testuv run doppler-test- If API/schema changed:
uv run openapi
Optional targeted runs:
- Smoke:
uv run doppler-test -m smoke -v - E2E integration:
uv run doppler-test -m e2e_integration -v - Autonomous local suite:
uv run autonomous-live-test
9) Agent Behavior Contract
All agents should:
- Prefer repository scripts over ad-hoc commands.
- Keep changes minimal, explicit, and reversible.
- Preserve existing behavior unless change is requested.
- Avoid destructive git operations.
- Avoid introducing new tooling without clear benefit.
- Keep docs and implementation aligned.
If unsure, trust these sources in order:
- Code in
app/,cli/,scripts/ pyproject.tomlscripts and config- Generated
docs/03-api/openapi.json - This file (
AGENTS.md) - Other docs