41 lines
6.1 KiB
Markdown
41 lines
6.1 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
|
|
- Write Russian UI and bot copy for CatWar faction members. Preserve ЛУ/ЗУ, бельчата, белки-летяги, кураторы, осмотры, resource names, command examples, and rule limits. Prefer plain instructions; explain name/ID lookup without internal terms such as «связка». Keep required input separators and report templates intact when editing prose.
|
|
- 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
|
|
- Weather easter egg: `python -m unittest discover -s tests -p test_weather.py -q` and `node --check web/weather-effect.js`; inspect `/belki` and `/admin` with rain/snow/mixed fixtures, mobile widths, reduced motion, and API failure. Prefer the remote test-zone MCP when exposed; otherwise use an isolated local server with temporary SQLite paths and stop it after validation. Keep screenshots outside the repo.
|
|
- 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
|
|
- `app/belki/weather.py` reads only the fixed public ULLI raw METAR endpoint (3-second timeout, 64 KiB bound, 5-minute process cache, 1-minute failure cache). `/api/weather/ulli` exposes only decoration settings; shared CSS/JS live at `/api/weather/effect.css` and `/api/weather/effect.js` so the existing gateway `/api/` route handles them. Keep weather independent of reports/storage, skip trend/remark/vicinity groups, reject observations older than 2 hours, and retain leaves on failure. Do not disable TLS verification.
|
|
- 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.
|