Commit Graph

7 Commits

Author SHA1 Message Date
Stefan 35ba74e5c0 scripts 2025-12-15 14:54:27 +01:00
Stefan 7383af7884 fix 2025-12-15 14:34:23 +01:00
Stefan 014781e2d0 feat: add Wikipedia integration to opening database
- Added wikipediaSlug field to 8,698 openings across all ECO files
- Rebuilt moveIndex.json with Wikipedia slug references
- Updated docker-entrypoint.sh to rebuild index after slug updates

This enables Wikipedia summaries for openings like:
- King's Gambit (king-s-gambit)
- Ruy Lopez (ruy-lopez)
- And 65 other opening families

The Wikipedia integration provides historical context and strategic
explanations for openings during training sessions.
2025-12-08 16:51:03 +01:00
Stefan 8ed402bbe0 feat: improve opening trainer flow and add deviation dialog
- Add tutor message guardrail to prevent rapid-fire messages
  - Track last message by move index
  - Wait for both player and opponent moves before speaking
  - Speak immediately when player deviates from theory

- Add deviation dialog with three options:
  - Continue Playing (Start Game) - transitions to game mode
  - Undo & Return to Opening - returns to theory
  - Explore This Variation - continues off-book practice

- Implement smooth game mode transition:
  - Pass opening context from trainer to game
  - Tutor welcomes player with context about their study
  - Computer makes first move if needed in starting position

- Fix generate-test-fixtures script:
  - Add safety check to prevent overwriting real data
  - Restore full opening database (12,379 openings)
  - Rebuild move index (12,377 sequences)
  - Add clear warnings about test fixtures

- Update ChessGame to accept openingContext prop
- Update Tutor to display contextual greeting in game mode

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-08 15:05:05 +01:00
Stefan 002ed92bea Add mobile app support and opening training feature
This commit implements iOS/Android mobile app support using Capacitor
and adds a comprehensive opening training feature with LLM-powered
explanations.

## Mobile App Infrastructure

- Add Capacitor configuration for iOS/Android builds
- Create mobile build script that excludes API routes
- Update Next.js config for conditional static export
- Add layout components with generateStaticParams for static builds
- Generate 500+ static pages for offline mobile use

## Chess Engine Abstraction

- Create ChessEngine interface for pluggable implementations
- Add LocalEngine (GPL - uses stockfish.js in browser)
- Add RemoteEngine (proprietary - calls API server)
- Factory pattern selects engine based on environment
- Enables GPL compliance for web, proprietary for mobile

## Opening Training Feature

- Interactive opening repertoire training
- Move validation with engine-backed feedback
- LLM explanations using Gemini API
- Wikipedia integration for opening context
- Opening family grouping (e4, d4, c4, etc.)
- Session state management
- Real-time move feedback with evaluation

Components:
- OpeningSelector: Browse and select openings by family
- OpeningTrainer: Main training interface with chessboard
- MoveFeedback: Display move quality and LLM explanations
- WikipediaSummary: Show opening history and context
- ErrorBoundary: Graceful error handling

Services:
- openingLoader: Load and filter opening database
- engineService: Engine evaluation wrapper
- moveValidator: Validate moves against repertoire
- feedbackGenerator: Generate contextual feedback
- wikipediaService: Fetch and cache Wikipedia data
- sessionManager: Track training session state

## Wikipedia Integration

- Automatic Wikipedia article fetching for openings
- Client-side and server-side caching
- Sanitized summaries with proper formatting
- Link opening database to Wikipedia slugs
- API endpoints for on-demand fetching

## Docker Improvements

- Add entrypoint script for automatic data setup
- Fetch Wikipedia data on first container startup
- Generate opening move index automatically
- Remove generated data from git (public/openings/*.json, public/wikipedia/*.json)
- Add READMEs explaining data requirements
- Update .gitignore for generated files

## Dual Licensing Strategy

- Add LICENSING.md explaining dual licensing approach
- GPL-3.0 for web builds (includes Stockfish)
- Proprietary option for mobile builds (no GPL code)
- Single codebase, multiple licensing models
- Legal compliance documented

## API Endpoints

- POST /api/v1/llm/opening-explanation - Get LLM move explanations
- GET /api/v1/wikipedia/summary - Fetch Wikipedia summaries

## Type Updates

- Add openingTraining types
- Update Tutor component to use ChessEngine interface
- Add Gemini error handling types

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 18:40:58 +01:00
Stefan 878d469eb0 feat: Improve opening detection with hybrid exact + continuation approach
- Return exact match first (e.g., King's Pawn Game for 1.e4 e5)
- Fill remaining slots with common continuations (Ruy Lopez, Italian Game, etc.)
- Look up to 4 moves deeper to find important opening variations
- Prioritize by depth (closer continuations first), then ECO root flag, then ECO code
- Avoid duplicate ECO families (e.g., don't show multiple C6x openings)
- Add isEcoRoot field to OpeningMetadata interface
- Add test script to verify opening lookup logic

Example: After 1.e4 e5, now returns:
1. King's Pawn Game (C20) - exact match
2. King's Gambit (C30) - continuation
3. King's Knight Opening (C40) - continuation
4. Ruy Lopez (C60) - continuation
5. Italian Game (C50) - continuation

This gives users context about what openings are still possible.
2025-11-27 20:21:45 +01:00
Stefan 3c1ace6aea feat: Add opening move sequence index
- Create buildOpeningIndex.js script to generate moveIndex.json
- Generate moveIndex.json with 12,377 unique move sequences
- Index maps move sequences to arrays of opening metadata
- Sorted by move length then alphabetically
- File size: 4.07 MB
- Enables fast lookup of multiple possible openings from move sequences
2025-11-27 12:26:58 +01:00