Files
cwshed-clone/AGENTS.md
T

12 KiB
Raw Blame History

AGENTS.md

Scope

  • This repository contains the Belki calculator/VK bot plus legacy CatWar userscript assets.
  • Key files: app/, web/calculator.html, Dockerfile, and deploy/k8s/.
  • LongMemory namespace is explicitly catwar, established by the owner on 2026-11-14 and recorded in root project-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_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.
  • CI may only read and patch the existing belki-runtime Secret; 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, so BELKI_ADMIN_RATE_LIMIT_EXEMPT_PROXY_CIDRS skips 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 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.
  • CI builds the Belki dependency base from Dockerfile.base and requirements.txt. For Nginx version updates, pin the upstream Linux amd64 image digest in Dockerfile.gateway-base, publish a new immutable tag to reg.nyan404.ru/cwshed/cwshed-base, and set its tag and digest in Dockerfile.gateway before running CI.
  • 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

  • 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 shared entered flag and admin authorization.
  • Frontend regression: node tests/browser/calculator.cjs against a separately started isolated server at http://127.0.0.1:8876 (override BELKI_TEST_URL only 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 by load_workspace_dependencies, setting NODE_PATH to its node_modules and optionally CHROMIUM_PATH to 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 launch python -m app.main with BELKI_DATABASE_URL=, BELKI_HOST=127.0.0.1, BELKI_PORT=8876, and temporary absolute paths for BELKI_HISTORY_DB and BELKI_IDENTITIES_DB. Never reuse production stores. BELKI_SCREENSHOT_DIR optionally 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 -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 Nginx upgrades, check nginx -v and nginx -t on the built gateway release. An isolated syntax check can resolve the Kubernetes hostname with --network none --add-host belki-bot:127.0.0.1.
  • Python 3.12 slim does not recognize WebP in strict mimetypes.guess_type() without system MIME data. Keep the explicit image/webp response in Handler._file; tests.test_lu_trainer covers a missing MIME mapping. Do not rely only on workstation MIME tables when adding media formats.
  • 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

  • LU trainer is implemented at /trainer and /trainer/ through both Python and Nginx. web/lu-trainer/engine.js is DOM-free; UI consumes public snapshots without hidden hazards/values. Keep notes separate from facts, map selection separate from jumping, jumps limited to the eight neighbors of the current position, and transition cells outside victory counts. Entrance is fixed at x1 y1 (top-left); choose each field's exit from x10 y2–y6 or y6 x6–x10. UI/map must use snapshot transition identities, never a global exit constant. Coordinates are one-based X right/Y down. Preserve documented training formulas; do not claim they are verified CatWar rules. Original art provenance is in web/lu-trainer/assets/README.md.
  • Trainer controls: click/Enter/Space jumps; with focus on the scene, physical WASD keys jump one cell from the current position in four directions, without key repeat. Arrows move focus only; right-click or Shift+Enter on the scene toggles a mark. Compact and coarse-pointer layouts use selection plus buttons under the field, without a separate action-mode switch. Keep the field status brief and the detailed jump message in the journal.
  • Trainer map ratings 0–7 are independent of verified values and hazard flags; null means no rating, 0 means no danger around the cell. Sound mode hides numeric facts and LU hints during play; simplified mode reveals the level of opened cells and the entrance. audio.js generates cues locally and starts playback only via an action or replay.
  • Keep the phone map below the scene on the same scrollable page. The safe start x1 y1 is not a transition; it can be revisited from an adjacent cell but does not count as opened or accept marks/ratings. Only the exit remains an impassable transition. The start has 0–2 neighboring hazards, x1 y2 at most 3 and x1 y3 at most 4. Apply those limits to generated hazards, not displayed values. The start number is visible in simplified mode and after the attempt.
  • LU checks (prefer remote test-zone MCP when exposed): Node 24 node --test tests/lu-trainer/engine.test.mjs; isolated Python python -m unittest tests.test_lu_trainer tests.test_calculator_web -q; node --check web/lu-trainer/ui.js; node tests/browser/lu-trainer.cjs with the same bundled Playwright, loopback server and temporary stores as the calculator suite. No npm install or runtime dependency is needed. Browser coverage includes 1920/1366/768/390 widths, mouse/touch/keyboard, map projection, clear/restart confirmation, result locks, hints/timers, 200% layout and failed images. Inspect screenshots outside Git. Nginx aliases must serve the same HTML and correct asset MIME types; do not deploy to validate a client-only change.
  • 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 patches both into the existing 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 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.