mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
## Summary - Replace automatic welcome/feedback credit grants with AI-powered abuse evaluation using Gemini 3.1 Pro - **Fail-closed**: errors/uncertainty → credits withheld, admin notified via email with user admin link - Clean users (no correlations) get instant grant with no AI call latency - Frontend verify page shows preparing account → celebratory/denied/pending interstitial - Comprehensive docs at `docs/AI-CREDIT-GATING.md` ## Changes | File | What | |------|------| | `backend/services/credit_evaluation_service.py` | **New**: Signal collection, Gemini prompt, response parsing, Firestore audit | | `backend/config.py` | `CREDIT_EVAL_ENABLED`, `CREDIT_EVAL_MODEL` config | | `backend/services/user_service.py` | Welcome credit flow integration (returns tuple) | | `backend/api/routes/users.py` | Feedback credit + verify response integration | | `backend/services/email_service.py` | `send_credit_denied_email()`, `send_credit_review_needed_email()` | | `backend/models/user.py` | `credit_status` field on verify response | | `frontend/app/auth/verify/page.tsx` | 5-state interstitial flow | | `frontend/lib/types.ts` + `auth.ts` | Type + state updates | | `backend/tests/test_credit_evaluation.py` | **New**: 17 tests | | `backend/tests/test_anti_abuse.py` | Updated for new return type | | `docs/AI-CREDIT-GATING.md` | **New**: Comprehensive documentation | | `pyproject.toml` | `google-generativeai` dep, version bump | ## Test plan - [x] 50 backend tests pass (17 new + 33 updated) - [ ] Manual: test with new account signup in prod (see docs for expected flow) - [ ] Manual: verify admin review email received for error cases ## Rollback Set `CREDIT_EVAL_ENABLED=false` in Cloud Run env vars → instant revert to auto-grant. @coderabbitai ignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>