Files
cwshed-clone/AGENTS.md
T

38 lines
4.8 KiB
Markdown

# AGENTS.md
## Scope
- This repository contains the Belki calculator/VK bot plus legacy CatWar userscript assets.
- Key files: [`app/`](./app), [`web/calculator.html`](./web/calculator.html), [`Dockerfile`](./Dockerfile), and [`deploy/k8s/`](./deploy/k8s).
## Working Rules
- Keep the calculation domain independent from HTTP, VK, and Kubernetes.
- Keep VK tokens and group IDs out of the repository; use environment variables or Kubernetes Secrets.
- Keep `VK_CALLBACK_SECRET` private as well: VK sends it in the top-level `secret` field, it is at most 50 characters, and it must never appear in URLs, logs, responses, or committed documentation.
- Production manifests are already applied in namespace `belki`; CI deploys them from `main` using the namespace-scoped RBAC in [`deploy/k8s/rbac.yaml`](./deploy/k8s/rbac.yaml).
- The production build uses the GitLab runner tag `fast`, a privileged Docker executor, and an explicit `docker:29.6.1-dind` service alias over TCP.
- Production images and Kubernetes workloads are amd64-only. Preserve `linux/amd64` in Dockerfiles, CI build commands, and workload node selectors; do not reintroduce the arm64-only Python base tag.
- When adding, removing, or updating a runtime dependency, rebuild and push the matching immutable base image to `reg.nyan404.ru`, then update its tag in the final Dockerfile before running CI. `requirements.txt` maps to `Dockerfile.base`; `nginx.conf` maps to `Dockerfile.gateway-base`.
- Use Context7 for current official documentation when implementing or changing an external API, framework, or library integration.
- Before adding or updating any dependency, use `prevent-eol` to check lifecycle support; do not treat its results as a vulnerability assessment.
- For web UI work, use the project-local `.codex/skills/frontend-craft`, `.codex/skills/frontend-design`, and `.codex/skills/ui-ux-pro-max` instructions: establish a deliberate visual direction, preserve accessibility and interaction quality, then inspect the rendered result.
## Validation
- For CI-only changes, prefer a targeted YAML parse and a diff review.
- For image/runtime changes, check the `Dockerfile`, Python entrypoint, static asset serving, and CI job together.
- For k3s changes, validate YAML and current cluster inventory first; keep `KUBE_CONFIG_B64` masked/protected in GitLab.
- Do not add unnecessary local build artifacts or temporary files to the repository.
- Admin report UI changes should cover both the persisted history flag and browser behavior: run the focused history/admin filter tests, Python compilation, `git diff --check`, and a JavaScript syntax check for `web/admin.html`. The report list defaults to the calendar current month; do not silently replace the existing sort order.
- Public report lookup is `GET /api/reports?character_id=<cat ID>`; it searches saved report participant IDs, returns at most 100 newest rows without `actor_id`, and is covered by `tests/test_report_lookup.py`. VK `/мои-отчёты` uses the callback sender ID and the same history store; validate with `python -m unittest tests.test_report_lookup tests.test_history tests.test_vk_bot -q`.
## Notes
- VK scheduler lives in `app/belki/vk_scheduler.py`; use `BELKI_DATABASE_URL` in production and `BELKI_HISTORY_DB` for local SQLite checks. Keep mailing disabled until an administrator explicitly enables a conversation and schedule.
- VK Callback API and dialog durability live across `app/belki/vk_bot.py`, `app/belki/vk_callback.py`, and `app/belki/vk_scheduler.py`. The bot listens on callback port 8081; preserve `vk_dialog_states` and `vk_callback_events` when changing dialog steps, attachments, or event dispatch. Validate with `python -m unittest tests.test_vk_bot tests.test_vk_conversation -q`. Production uses `/api/vk/callback` on the existing public host and routes that exact path to the `belki-bot` Service.
- The build job waits for the DinD daemon and runs `docker info` before building.
- The deploy job requires protected CI variables `VK_CALLBACK_SECRET` and `VK_CALLBACK_CONFIRMATION` and writes both into `belki-runtime` before applying the bot Deployment.
- Never commit `.env` or `.gitlab.variables.env`; the latter contains the GitLab Variable handoff and a namespace-scoped kubeconfig.
- Private image storage is the separate Kubernetes Secret `belki-image-store`, not the CI-recreated `belki-runtime`. It contains only the internal MinIO endpoints and bucket-scoped credentials; keep MinIO private and preserve the `/api/images/<id>` Belki proxy when changing upload flows.
## Agent Rules
- Zod `.describe()` on optional fields: always append `.optional()` — e.g. `zod.string().describe("…").optional()` — to avoid validation failures when the field is absent.
- After completing a task, create one or more focused, logical Git commits; do not push unless the user explicitly asks.