refactor: comprehensive codebase cleanup and architecture hardening

- Sprint 1 (Quick Wins): Remove dead analytics modules, fix 4 unresolved
  imports, replace 3 console.warn with logger, remove mock-crc import
- Sprint 2 (Architecture): Create MascotChatRepository, AnalysisRepository,
  3 Zod schemas (mascot-chat, analysis, voice), deduplicate error classes,
  move 3 SQL queries from routes to repository
- Sprint 3 (Complexity): Replace 7 any types with proper interfaces,
  extract 6 helpers from prepareMediaMessage (CC 85 -> ~15)
- Sprint 4 (Config): Remove 22 dead env vars from .env, add 30 missing
  vars to .env.example, standardize naming

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-09 10:16:04 +07:00
co-authored by Claude Opus 4.8
parent d0d9e1669e
commit 4becf0d6f1
89 changed files with 1260 additions and 5499 deletions
+51 -1
View File
@@ -1,5 +1,8 @@
# Discord Bot Configuration
DISCORD_TOKEN=your_bot_token_here
MONITOR_GUILD_ID=your_guild_id_here
TEXT_GUILD_ID=optional_text_guild_id
TEXT_CHANNEL_ID=optional_text_channel_id
# Recording Configuration
RECORDINGS_DIR=./recordings
@@ -50,6 +53,39 @@ AI_LLM_BASE_URL=https://9router.asepharyana.tech/v1
AI_LLM_MODEL=free
# Vision model for image/video moderation (falls back to AI_LLM_MODEL if unset)
AI_LLM_VISION_MODEL=multimodal
# Max concurrent LLM API calls (default: 5)
AI_LLM_MAX_CONCURRENT=5
# Maximum image dimension in pixels before resize for vision API (default: 1024)
AI_LLM_IMAGE_MAX_DIMENSION=1024
# Maximum messages per text-only moderation batch (default: 20)
AI_LLM_TEXT_BATCH_SIZE=20
# Timeout in ms for individual media analysis calls (default: 60000)
AI_LLM_MEDIA_ANALYSIS_TIMEOUT_MS=60000
# AI Moderation Analysis Tuning (advanced)
AI_ANALYSIS_DEBOUNCE_MS=500
AI_ANALYSIS_RECOVERY_INTERVAL_MS=15000
AI_ANALYSIS_ERROR_COOLDOWN_MS=30000
# Max messages fetched per conversation batch (default: 200)
AI_ANALYSIS_MAX_BATCH_SIZE=200
AI_ANALYSIS_MAX_CONTEXT_TOKENS=8000
# Token budget for target messages specifically (default: 4000)
AI_ANALYSIS_MAX_TARGET_TOKENS=4000
AI_ANALYSIS_CONTEXT_MESSAGE_LIMIT=20
# How long a conversation is locked while being processed (default: 120000ms)
AI_ANALYSIS_PROCESSING_TIMEOUT_MS=120000
# Max concurrent individual-fallback jobs (default: 50)
AI_ANALYSIS_INDIVIDUAL_MAX_CONCURRENT=50
# Consecutive errors before individual circuit breaker trips (default: 50)
AI_ANALYSIS_INDIVIDUAL_CB_THRESHOLD=50
# OpenAI Moderation (optional separate provider)
# OPENAI_MODERATION_API_KEY=your_key_here
# OPENAI_MODERATION_BASE_URL=https://api.openai.com/v1
# OPENAI_MODERATION_MODEL=omni-moderation-latest
# Admin
ADMIN_PASSWORD=admin123
# Database Configuration (PostgreSQL)
# Option 1: Use DATABASE_URL for connection string
@@ -72,22 +108,36 @@ AI_LLM_VISION_MODEL=multimodal
# Auto-Delete Configuration
AUTO_DELETE_FLAGGED_ENABLED=true
AUTO_DELETE_FLAGGED_DRY_RUN=true
AUTO_DELETE_FLAGGED_DELAY_MS=0
AUTO_DELETE_MIN_CONFIDENCE=0.50
AUTO_DELETE_ALLOWED_SEVERITIES=critical,high,medium
AUTO_DELETE_NOTIFY_USER=false
# Optional: comma-separated channel/user IDs to exclude
# AUTO_DELETE_EXCLUDED_CHANNEL_IDS=
# AUTO_DELETE_EXCLUDED_USER_IDS=
# Optional: comma-separated category filter (empty = all categories)
# AUTO_DELETE_ALLOWED_CATEGORIES=
# Optional: log channel ID for auto-delete actions
# AUTO_DELETE_LOG_CHANNEL_ID=
# Retention Configuration (0 = disabled)
RETENTION_MESSAGES_DAYS=0
RETENTION_ATTACHMENTS_DAYS=0
RETENTION_VOICE_DAYS=0
# Cleanup interval in ms (default: 24h)
RETENTION_CLEANUP_INTERVAL_MS=86400000
RETENTION_DRY_RUN=true
# Database Migration Configuration
# Safe default: run migrations on startup before the app accepts traffic.
AUTO_MIGRATE_ON_STARTUP=true
# Worker Pool Configuration
# PISCINA_MAX_THREADS=4
# Cache Model Versioning
# Bump this version when the vision/LLM model prompt changes significantly.
# Old cache entries with mismatched versions are automatically ignored, forcing fresh analysis.
# Format: "v<N>" or "v<N>-<date>-<description>"
# Example progression: v1 → v2-2026-06-02-terminal-fix → v3-2026-06-15-new-model
# CACHE_MODEL_VERSION=v2-2026-06-02