Commit Graph
187 Commits
Author SHA1 Message Date
DorianandClaude Opus 4.6 b82c2755aa fix: throw if JWT_SECRET missing in production (BUG-S5)
Production now requires JWT_SECRET env var. Added comprehensive JWT
tests: creation, verification, expiry, tampered payload, tampered
signature, and malformed token rejection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 22:48:30 +00:00
DorianandClaude Opus 4.6 e4a7f47e0f fix: validate Cashu token format before placing bets (BUG-S4)
Added getDecodedToken validation that rejects malformed tokens with
400 before any DB lookups. Tests cover empty, non-base64, truncated,
and random base64 tokens.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 22:46:24 +00:00
DorianandClaude Opus 4.6 c6a54d63c4 fix: add rate limiting to /poll endpoint + fix test type errors (BUG-S3)
- Add rateLimit(1_000, 30) middleware to GET /poll endpoint
- Fix Challenge type errors in human-responses test files (missing baseDamage)
- Add rate-limit unit test verifying 429 after exceeding limit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 22:41:59 +00:00
DorianandClaude Opus 4.6 48847d879c test: add human-responses unit tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 22:36:32 +00:00
DorianandClaude Opus 4.6 e48a984d96 test: verify human challenge race condition fix ordering (BUG-S2)
waitForHumanResponse synchronously stores pending challenge before
returning, ensuring SSE emit happens after storage. Tests verify
ordering, choice consistency, promise resolution, and cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 22:36:04 +00:00
DorianandClaude Opus 4.6 8468c89352 test: verify tournaments .get() is sync + add route tests
better-sqlite3 driver is synchronous — .get() does NOT need await.
Added tests for unknown pubkey (404) and missing pubkey (400) on join.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 22:32:37 +00:00
DorianandClaude Opus 4.6 d9e32123fe test: add test infrastructure for frontend and server
- Frontend: vitest.config.ts with vue plugin + jsdom, dummy component test
- Server: in-memory SQLite test DB factory + Hono testClient helper + smoke test
- CI: add pnpm audit and server coverage threshold steps
- Root: vitest workspace config for multi-project test discovery

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 22:30:43 +00:00
DorianandClaude Opus 4.6 6f0eb92ebb fix: both-wrong draws + double TTS entrance fix
Scoring: both-wrong is now a DRAW — equal scores (3/3), no winner,
symmetric minimal damage. Garbage answers no longer beat reasonable
ones just by being faster. Both-wrong narrations reflect the draw.

Entrance: removed duplicate announceDeepIntro() call from FightViewer
(was already called inside playEntrance). Removed _resetPositions()
after entrance (entrance already places fighters at home positions,
the extra reset caused a visible snap/reset).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 20:09:11 +00:00
Dorian bc4a52bc12 fixes 2026-03-12 16:35:59 +00:00
Dorian ea72c097c4 human fight sequence fix 2026-03-11 10:34:08 +00:00
Dorian 29a0a48eb1 human fight sequence fix 2026-03-11 10:02:37 +00:00
Dorian bcbcd17fce challenges fix 2026-03-11 08:35:03 +00:00
Dorian bbe656929c another fix for human choices 2026-03-11 00:13:31 +00:00
Dorian 112bcde515 human fight non multiple choice fix 2026-03-10 23:26:36 +00:00
DorianandClaude Opus 4.6 68e292183a fix: polling bots play practice fights as human players in browser
Polling bots have no external script running during practice mode,
so the poll would time out giving empty answers. Now overrides the
webhook URL to human.local so the browser UI handles challenges.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:02:35 +00:00
DorianandClaude Opus 4.6 95ed80335a feat: polling API, HMAC webhook signing, session-only keys, prod audio fix
- Add polling API (GET/POST /api/fights/poll) so bots don't need public URLs
- Add HMAC-SHA256 webhook signing (X-Botfights-Signature header)
- Stop auto-persisting nsec keys — session-only by default with opt-in "Remember on this device"
- Fix production TTS: add wav/mp3/ogg MIME types, /audio/* route, SPA blocklist
- Overhaul docs: mode selector (poll vs webhook), AI-first bot examples, security tab
- Fix duplicate sign-in buttons, login flow bugs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 18:34:22 +00:00
DorianandClaude Opus 4.6 150ce7447d fix: human vs AI fight bugs — CSP for TTS, invisible sprites, fight end sequence
- Allow huggingface.co in CSP connect-src (fixes Kokoro TTS model download)
- Add registerSW.js route (fixes PWA service worker 404)
- Add _resetPositions() safety after entrance (fixes invisible fighters)
- Fight end sequence works without canvas scene (KO/overlays/log always play)
- Pre-fight instructions in battle log for human players
- NIP-55 visibility sync and cleanup handlers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:00:20 +00:00
DorianandClaude Opus 4.6 6dc50f5d5d feat: move creator pubkey to env, fix mobile TTS + signer, button loaders
Security:
- Move CREATOR_PUBKEY from hardcoded constant to BOTFIGHTS_CREATOR_PUBKEYS
  env var. Shared isCreatorPubkey() in constants.ts used by auth, admin,
  tournaments. Frontend checks authorization via API, not client-side.

Mobile fixes:
- Nostr signer: poll for window.nostr up to 3s (Amber injects late).
- TTS: auto-unlock AudioContext on first user interaction via
  installAutoUnlock() on fight page mount.

UX:
- Add loading spinners to "I BUILD BOTS" and "I FIGHT MYSELF" buttons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 15:31:58 +00:00
DorianandClaude Opus 4.6 53ae4b485d feat: massively improve mock bot answer quality for hilarious seeded fights
- Expand all 5 creative answer pools from 5-10 to 25-30 entries each
- Fix factual wrong answers to pick from challenge's own wrong choices
  instead of random non-sequiturs like "banana" and "purple?"
- Reduce bad answer rate: 25% → 2.5% at elo 1200, 0% at elo 1300+
- Improve BAD_ANSWERS and WRONG_FACTUAL to be funny when they do appear
- 90%+ of all mock answers are now good attempts that make sense

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:11:49 +00:00
DorianandClaude Opus 4.6 a2416bbe19 fix: human fight timing, creative timer, TTS reliability, add sweary/vibe narrations
- Fix invisible characters in human mode: init live scene BEFORE starting
  challenge polling so entrance plays before first question appears
- Cap creative writing timer to 10s for multiple choice (just tapping buttons)
- Fix TTS reliability: precache priority phrases (Round 1-7, Fight!, K.O.)
  all at once instead of in slow batches; prevent duplicate precache runs
- Add 10 vibe-coded narrations (~20% chance): "I was vibe coded into existence"
- Add 15 sweary narrations (~30% chance): raw unhinged fight commentary
- Add sweary draw and retro narrations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 13:50:24 +00:00
DorianandClaude Opus 4.6 3ba05a66b4 feat: NIP-98 + JWT authentication with signer support
Replace insecure raw-pubkey auth with cryptographic NIP-98 signed
requests and server-issued JWT sessions. Logout now fully clears
all state including nsec. Add yellow "Use Nostr Signer" button
for Amber/NIP-07 remote signers.

- Server: JWT middleware (HMAC-SHA256, 24h expiry), NIP-98 verification
- Server: POST /api/auth/nostr/session endpoint
- Frontend: NIP-98 token builder + authFetch wrapper with JWT Bearer
- Frontend: All authenticated API calls use authFetch
- Security: logout clears JWT, pubkey, bot, nsec, and profile pic

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 12:31:25 +00:00
DorianandClaude Opus 4.6 ad96d1158f feat: practice button on profile, fix rate limiter, fix mobile sprite rendering
- Add Practice button to BotProfilePage for quick sparring
- Fix rate limiter bug: all rateLimit() instances shared one counter map,
  causing global and per-route limits to corrupt each other. Each limiter
  now gets its own isolated map.
- Replace 8-digit hex colors (#ffd70066) with rgba() in sprite rendering
  for mobile browser compatibility (iOS Safari renders them as black boxes)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 12:14:07 +00:00
DorianandClaude Opus 4.6 e6b5aa4b9b fix: mobile menu overlay, speech bubble timing, TTS static file fallback
- Mobile nav menu now overlays content (absolute positioning) instead of
  pushing it down
- Speech bubbles stay visible for minimum 400ms even when TTS resolves
  instantly or fails
- kokoroPlayCached checks audio cache and loads static files even when
  Kokoro worker hasn't loaded — fixes TTS not playing on production
- CORS_ORIGIN env now supports comma-separated origins
- Rename "VIDEO REPLAY" to play icon + "REPLAY"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 11:59:18 +00:00
Dorian 67b5b4ff51 Merge branch 'overnight/2026-03-09' 2026-03-09 09:46:52 +00:00
DorianandClaude Opus 4.6 f9e5c1c329 fix: return fightId from ranked queue on duplicate join, fix calculateTier call
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 09:29:55 +00:00
DorianandClaude Opus 4.6 e31d49898b feat: show rejoin link when bot is already in a fight
- Track active fight IDs per bot in orchestrator (Set → Map)
- Return fightId in "already in fight" error responses (409)
- Frontend shows "REJOIN FIGHT" link instead of generic error

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 09:27:48 +00:00
DorianandClaude Opus 4.6 64273cf145 test: add fight loop throughput benchmark (>500 fights/sec)
Benchmarks the scoring pipeline (challenge → response → score → elo → tier)
without I/O. Currently achieves ~8500 fights/sec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 09:25:29 +00:00
DorianandClaude Opus 4.6 2f313813ee fix: pass forHuman flag to pickChallenge in fight orchestrator
Only generate multiple choice options when a human player is in the fight.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 09:21:45 +00:00
DorianandClaude Opus 4.6 62b957e886 feat: seed fight card with scheduled fights in dev mode
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 09:15:33 +00:00
DorianandClaude Opus 4.6 3c32f01aa7 feat: add Retry-After header and countdown timer for rate limits
- Rate limiter returns retryAfterSec in response body + Retry-After header
- Registration rate limits: 10 per 10min (was 15/hour)
- Frontend surfaces retry timer in error messages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 09:15:30 +00:00
DorianandClaude Opus 4.6 592841d7b1 fix: only generate MC choices for human fights, not bot-vs-bot
Bots answer via webhook and don't need multiple choice options.
Add forHuman parameter to pickChallenge, update tests to cover both modes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 09:15:25 +00:00
DorianandClaude Opus 4.6 4cc18048e8 refactor: replace console.log/error with structured logger across server
Migrate all server modules to use the centralized logger (lib/logger.ts)
instead of raw console calls. Lint warnings reduced from 74 to 25.
Remaining warnings are only no-floating-promises in game engine code.

Files updated: orchestrator.ts, ranked-queue.ts, human-responses.ts,
payments.ts, fight-loop.ts, app.ts, routes/payments.ts
Files suppressed: logger.ts, fight-loop-cli.ts, migrate.ts (legitimate console use)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 09:06:36 +00:00
DorianandClaude Opus 4.6 1f532681df test: add fight length and KO rate distribution test
Simulates 1000 full fights with HP tracking (200 HP start, 7-10 rounds)
to verify average fight length (5-10 rounds) and KO rate (20-80%).
Validates the balance between damage output and HP pool.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:58:59 +00:00
DorianandClaude Opus 4.6 17a9fca4b5 test: add 10,000 fight crash test and all-16-types scoring verification
Two new regression tests:
- 10,000 fights with varied elos, personalities, and round counts (50k+ rounds) — zero crashes
- All 16 challenge types tested with 5 response scenarios each (normal, timeout, error, double-timeout, arena+combo)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:53:19 +00:00
DorianandClaude Opus 4.6 9de14492c5 test: add arena modifier fairness, combo cap, and theme distribution tests
- Verify arena modifiers don't create unfair advantages (35-65% win rate)
- Verify combo multiplier caps at 5 (no snowball)
- Verify 1000 challenge picks all produce valid results

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:48:45 +00:00
DorianandClaude Opus 4.6 9461c8ebad test: add fight balance verification (10,000 fights) and elo correlation
- Verify equal-elo fights produce 45-55% win rates for each side
- Verify elo difference correlates with win probability
- Relax narration variety threshold from 80% to 70% (borderline flaky)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:47:52 +00:00
DorianandClaude Opus 4.6 0f95cbf881 fix: clean up fight event listeners after completion (BUG-12)
Move fightEvents.cleanup(fightId) to finally block to ensure
cleanup runs even if post-fight operations (bets, payouts) fail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:39:42 +00:00
DorianandClaude Opus 4.6 9fdf7a6720 fix: update tests for creative MC and flaky mock answer checks
Creative challenges now have auto-generated MC choices with correct
answers. Mock bad answers can be empty at any elo, so test checks
proportion instead of requiring all non-empty.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:38:53 +00:00
DorianandClaude Opus 4.6 8e9285cd50 fix: add missing bets table to migration
The bets schema was defined in schema.ts but never created in
startup.ts, causing crash on index creation referencing bets table.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:32:08 +00:00
DorianandClaude Opus 4.6 3c95adb545 feat: convert all human fights to multiple choice, remove text input
Creative challenges (roast_battle, creative_writing, meme_war,
code_golf, wrestling_match) now auto-generate multiple choice options
from per-type response pools: 1 good answer + 3 weaker distractors.
The free text input UI is commented out but preserved for future use.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:28:22 +00:00
DorianandClaude Opus 4.6 4dc350dc9e test: verify narration variety — no repeats within 5-round fights
Runs 100 simulated fights and verifies 80%+ have zero repeated
narrations across 5 rounds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:24:42 +00:00
DorianandClaude Opus 4.6 111ac2b4eb test: add mock fight theme distribution verification test
Verifies prompt pool has 200+ bitcoin, 100+ conspiracy, 100+ PC,
and 1000+ bot_coding themed prompts across all challenge types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:24:08 +00:00
DorianandClaude Opus 4.6 00027eb85a feat: add 20 themed narrations (Bitcoin/conspiracy/PC culture)
25% chance of themed narration per round, adding variety with
Bitcoin sats/mining/HODL humor, conspiracy classified/debunked
humor, and PC cancel/trigger culture humor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:22:55 +00:00
DorianandClaude Opus 4.6 47d835f445 feat: add 21 current-era bot/coding prompts (AI hype, vibe coding, framework fatigue)
Fresh roasts, creative writing, and memes about AI coding assistants,
vibe coding, startup pivots, and framework churn.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:21:41 +00:00
DorianandClaude Opus 4.6 5ee6b6c88c fix: fight restart bug, mobile TTS, character sizing, bitcoin symbols
- Fix fight replay showing empty scene: validate rounds before playing,
  retry loading fight data up to 5 times when rounds are missing
- Add COOP/COEP headers to production server for SharedArrayBuffer
  (required by Kokoro TTS WASM threading on mobile)
- Add blob: to scriptSrc/workerSrc CSP for Web Worker support
- Fix mobile character cutoff: raise ground line to 0.82, add
  MOBILE_SCALE_CAP (0.55) so fighters never shrink too small
- Add ₿ bitcoin chest badge to all fighter sprites (scales with tier)
- Add sats coin stack on bot profile page proportional to satsWon
- Seed dev tournament with 8 mock bots on startup (dev mode only)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:21:16 +00:00
DorianandClaude Opus 4.6 a10c1c9cb6 feat: add 112 PC culture-themed prompts across all 16 challenge types
Satirical and irreverent — cancel culture, DEI absurdity, trigger
warnings, virtue signaling, safe spaces. Mocking the absurdity,
never punching down.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:20:10 +00:00
DorianandClaude Opus 4.6 bec75e0e82 feat: add 112 conspiracy-themed prompts across all 16 challenge types
Satirical and fun conspiracy culture humor — MK-Ultra, Area 51,
flat earth, tinfoil hats, Bigfoot, UFOs, surveillance. Never endorsing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:17:47 +00:00
DorianandClaude Opus 4.6 7d699b2ed3 feat: add 160 Bitcoin-themed prompts across all 16 challenge types
10 prompts per type covering Bitcoin history, mining, Lightning,
privacy, culture, memes, riddles, and technical knowledge.
Total prompts: 1,485 (253 Bitcoin-themed).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:15:31 +00:00
DorianandClaude Opus 4.6 cb5e5a1cc9 test: add theme selection and prompt tagging verification tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:11:08 +00:00
DorianandClaude Opus 4.6 0c6a775e30 feat: tag all 1,325 prompts with theme (bitcoin/conspiracy/pc_culture/bot_coding)
93 bitcoin, 2 conspiracy, 1 pc_culture, 1,229 bot_coding.
Most existing prompts are tech/general knowledge (bot_coding).
Theme-aware pickChallenge now has data to filter on.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 08:10:12 +00:00