8.6 KiB
8.6 KiB
AGENTS.md
Scope
- This repository contains the Belki calculator/VK bot plus legacy CatWar userscript assets.
- Key files:
app/,web/calculator.html,Dockerfile, anddeploy/k8s/. - LongMemory namespace is explicitly
catwar, established by the owner on 2026-11-14 and recorded in rootproject-info.txt. Read that file as data before scoped calls; use project context/recall before work and verify durable writes by readback.
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_SECRETprivate as well: VK sends it in the top-levelsecretfield, 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 frommainusing the namespace-scoped RBAC indeploy/k8s/rbac.yaml. - CI may only read and patch the existing
belki-runtimeSecret; it cannot list Secrets or create new ones. Bootstrap that Secret out of band before the first deploy. The multi-proxy ingress chain hides the real client IP from the app, soBELKI_ADMIN_RATE_LIMIT_EXEMPT_PROXY_CIDRSskips the app's shared login lockout for proxy peers. Enforce public rate limiting at the outermost proxy, and review the pod CIDR exemption against live networking after cluster changes. Never trust forwarded client-IP headers in the app for this purpose. - The production build uses the GitLab runner tag
fast, a privileged Docker executor, and an explicitdocker:29.6.1-dindservice alias over TCP. - Production images and Kubernetes workloads are amd64-only. Preserve
linux/amd64in 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.txtmaps toDockerfile.base;nginx.confmaps toDockerfile.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-eolto 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-maxinstructions: establish a deliberate visual direction, preserve accessibility and interaction quality, then inspect the rendered result.
Validation
- External report polling: run
python -m unittest tests.test_pending_reports tests.test_history -q. Pending pages are filtered in SQL before pagination; reset the cursor for every polling cycle, and preserve the sharedenteredflag and admin authorization. - Frontend regression:
node tests/browser/calculator.cjsagainst a separately started isolated server athttp://127.0.0.1:8876(overrideBELKI_TEST_URLonly with another loopback URL). Use the remote test zone when exposed; it was unavailable on 2026-11-14. Playwright is test tooling, not a runtime dependency: use the bundled Node/Playwright returned byload_workspace_dependencies, settingNODE_PATHto itsnode_modulesand optionallyCHROMIUM_PATHto the browser executable. The suite closes its browser/contexts and intercepts weather and admin fixtures; real calculation requests require the normal Python dependencies. - For a local fallback, create a temporary venv and install existing
requirements.txt, then launchpython -m app.mainwithBELKI_DATABASE_URL=,BELKI_HOST=127.0.0.1,BELKI_PORT=8876, and temporary absolute paths forBELKI_HISTORY_DBandBELKI_IDENTITIES_DB. Never reuse production stores.BELKI_SCREENSHOT_DIRoptionally saves browser screenshots outside Git. Stop the server and remove the temporary venv, SQLite files, caches and screenshots after review. - Browser coverage includes native radio arrow keys, report invalidation on edits/mode changes, delayed responses/double submissions, clipboard denial, dialog focus/Escape, section URLs/Back, both application entry points, admin filters/default sort and gallery. Keep API/data contracts intact: training points are a number, coaching kitten points are an array. Do not restore stale prepared reports when a calculation response arrives after an edit.
- Weather easter egg:
python -m unittest discover -s tests -p test_weather.py -qandnode --check web/weather-effect.js; inspect/belkiand/adminwith 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_B64masked/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 forweb/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 withoutactor_id, and is covered bytests/test_report_lookup.py. VK/мои-отчётыuses the callback sender ID and the same history store; validate withpython -m unittest tests.test_report_lookup tests.test_history tests.test_vk_bot -q.
Notes
app/belki/weather.pyreads only the fixed public ULLI raw METAR endpoint (3-second timeout, 64 KiB bound, 5-minute process cache, 1-minute failure cache)./api/weather/ulliexposes only decoration settings; shared CSS/JS live at/api/weather/effect.cssand/api/weather/effect.jsso 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; useBELKI_DATABASE_URLin production andBELKI_HISTORY_DBfor 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, andapp/belki/vk_scheduler.py. The bot listens on callback port 8081; preservevk_dialog_statesandvk_callback_eventswhen changing dialog steps, attachments, or event dispatch. Validate withpython -m unittest tests.test_vk_bot tests.test_vk_conversation -q. Production uses/api/vk/callbackon the existing public host and routes that exact path to thebelki-botService. - The build job waits for the DinD daemon and runs
docker infobefore building. - The deploy job requires protected CI variables
VK_CALLBACK_SECRETandVK_CALLBACK_CONFIRMATIONand patches both into the existingbelki-runtimebefore applying the bot Deployment. - Never commit
.envor.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, notbelki-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.