Commit Graph

81 Commits

Author SHA1 Message Date
Stefan 7383af7884 fix 2025-12-15 14:34:23 +01:00
Stefan b36b91cddd download script 2025-12-15 12:21:34 +01:00
Stefan 4ef4e2e4f4 imprint 2025-12-14 13:04:56 +01:00
Stefan 25666e7359 imprint 2025-12-14 12:48:55 +01:00
Stefan 38f2cb0f3b imprint 2025-12-14 12:45:33 +01:00
Stefan 1bee218cce translations 2025-12-14 11:52:39 +01:00
Claude 47c37487b3 refactor: code review improvements
- Add 30s timeout to Stockfish evaluation to prevent hanging promises
- Add FEN validation and depth cap (max 30) to Stockfish API route
- Create ErrorBoundary component with specialized fallbacks for chess game and tutor
- Extract useChessSounds hook for better audio management
- Add React.memo to EvaluationBar and CapturedPieces for performance
- Add useMemo to CapturedPieces for sorted pieces calculation
- Improve tacticDetection to return empty array instead of "none" type
- Add filterMeaningfulTactics and hasTactics helper functions
- Translate hardcoded UI strings (stockfishLevel, download, evalChange)
- Update translations for EN, DE, FR, IT, PL
- Add uuid to Jest transformIgnorePatterns for ESM compatibility
- Update tests to use new filterMeaningfulTactics function
2025-12-10 21:30:28 +00: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 8db8410ffe fix: resolve Docker build issues
- Update .gitignore to allow moveIndex.json (needed at build time)
- Exclude only eco*.json files (too large for git)
- Add uuid package dependency for sessionManager

Fixes:
- Next.js build error: Module not found moveIndex.json
- Build error: Module not found uuid
2025-12-08 16:31:03 +01:00
Stefan 3f096d39a3 docs: add CHANGELOG and update README with new features
- Create CHANGELOG.md documenting v1.1.0 release
- Update README with opening training mode details
- Update README with tactical practice mode details
- Reorganize README into learning modes section
- Add mobile app information
- Maintain dual licensing documentation

Key additions:
- Opening Training: 12,379 openings with AI guidance
- Tactical Practice: 8 patterns with 20+ puzzles each
- Enhanced game mode with opening context awareness
- Mobile support via Capacitor

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-08 15:54:02 +01:00
Stefan 0751d988c3 fix: restore full opening database after merge
- Restore all 12,379 openings from commit 8ed402b
- Rebuild move index with 12,377 sequences
- Fix merge issue that overwrote with test fixtures

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-08 15:12:49 +01:00
Stefan f3134bf6ce chore: update test configs and opening data
- Update jest.config.ts for new test structure
- Update playwright.config.ts for e2e test setup
- Update opening database files (12,379 entries)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-08 15:08:41 +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 1e78d8114e docs: clarify dual licensing requirements and App Store restrictions
Make it explicit why dual licensing is NECESSARY (not optional):
- App Store and Google Play terms are incompatible with GPL-3.0
- FSF considers App Store distribution a GPL violation
- Mobile builds must exclude GPL code for platform compliance

Also clarify:
- Only copyright holder (KaProblem) can distribute proprietary mobile apps
- Third parties cannot distribute GPL apps on app stores (platform restrictions)
- Third parties cannot create proprietary versions from this code
- Contributors grant dual licensing rights for App Store compliance

Updates:
- Add 'Why Dual Licensing?' section explaining App Store restrictions
- Update copyright holder to KaProblem (https://www.kaproblem.com)
- Add App Store compliance context throughout documentation
- Clarify that this protects copyright holder's exclusive distribution rights

This prevents:
- Third parties from releasing proprietary mobile apps
- Confusion about why dual licensing exists
- GPL violations on app stores

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 18:49:41 +01:00
Stefan d062fd738b chore: ignore generated iOS/Android directories
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 18:41:10 +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 52dd32eb15 e2e 2025-12-06 17:41:58 +01:00
Stefan 9ebca615c7 playwright 2025-12-06 17:37:44 +01:00
stefan-kp 743bda02bf Add tactic position generators and tests 2025-12-06 09:23:04 +01:00
Stefan 1b2159445d Document API endpoints in README
- Add comprehensive API documentation section
- Document Stockfish evaluation endpoint (POST /api/v1/stockfish)
- Document LLM chat endpoint (POST /api/v1/llm/chat)
- Document personalities endpoint (GET /api/v1/personalities)
- Include request/response examples and usage with curl
- Link to detailed API docs in docs/ folder
- No mention of specific use cases, just general API availability
2025-12-04 17:17:42 +01:00
stefan-kp e01ece4161 Add tests for LLM API endpoints 2025-12-04 10:30:28 +01:00
stefan-kp 32f93b9305 Add LLM tutor API endpoints 2025-12-04 10:30:23 +01:00
stefan-kp cab02cfefd Add Stockfish evaluation API endpoint 2025-12-03 21:30:39 +01:00
Stefan 3787696aa8 Replace system confirm dialog with styled resign confirmation modal
- Replace window.confirm() with a custom styled modal dialog
- Match existing modal styling (header, content, footer pattern)
- Add Flag icon and AlertTriangle warning icon
- Use localized Cancel button text from common translations
- Improved UX with X close button and proper button styling
2025-12-03 10:09:08 +01:00
Stefan 6aa7d5bdd8 Add confirmation dialog for resign button
- Add window.confirm() before resigning to prevent accidental resignation
- Add 'resignConfirm' translation key in all 5 languages (EN, DE, FR, IT, PL)
- Messages are localized and warn that the action cannot be undone
2025-12-03 09:05:17 +01:00
Stefan 41ca7ae187 Fix hanging test and update README with resign feature
- Fix page.test.tsx: Use stable mock router reference to prevent infinite loop
  The useRouter mock was returning a new object on every render, causing
  the useEffect with router dependency to re-run infinitely
- Update README to document resign button and analyze game features
2025-12-03 08:56:33 +01:00
stefan-kp f9a245742b Handle resignation coach response and add analysis option 2025-12-03 08:45:31 +01:00
Stefan 327f17ad39 Update README with new features
- Add Polish language to multi-language support
- Document game export feature (PGN/FEN download)
- Add saved games and game continuation feature
- Document settings management and Clear All Data feature
- Add comprehensive User Experience Features section covering:
  - Game management (save/resume/export)
  - Customization options (languages, personalities, colors)
  - Analysis tools (evaluation bar, opening explorer, position analysis)
  - Modern interface features (responsive design, dark mode)
- Update typical game flow to include new features
- Improve feature descriptions with more detail
2025-12-01 17:17:06 +01:00
Stefan 21f11ce1dd Add game download feature and fix missing moves in history
- Add download button to game history section with modal
- Support downloading game as PGN or current position as FEN
- Add translations for download feature in all 5 languages (EN, DE, FR, IT, PL)
- Fix bug where first moves were missing from history: now wait for evalP0 (pre-analysis) before allowing player moves
- This ensures all moves are properly tracked with evaluations and tactics detection
2025-12-01 12:19:29 +01:00
Stefan 870efbbff7 Add Clear All Data feature to settings page
- Add 'Clear All Data' button in Danger Zone section
- Implement confirmation dialog before clearing
- Clear all localStorage and redirect to onboarding
- Add translations for clearAllData, clearAllDataConfirm, and clearAllDataDescription in all 5 languages (EN, DE, FR, IT, PL)
- Style with red theme to indicate destructive action
2025-12-01 11:54:35 +01:00
Stefan 6acc7ecc1c Fix homepage layout and add Polish language support
- Reorganize StartScreen: Start New Game button always visible at top
- Move unfinished games section below the start button
- Remove '2.' prefix from startGame translations (all languages)
- Update startNewGame translations to be button-appropriate
- Fix TypeScript errors: Update GameImportModal, GameAnalysisModal, and GameOverModal to use SupportedLanguage type instead of hardcoded language union
- Delete local branches: codex/add-polish-as-ui-language and codex/add-option-to-continue-game-from-position
2025-12-01 11:49:12 +01:00
Stefan 13210c61ee Merge Polish language support 2025-12-01 11:24:03 +01:00
Stefan b69d0c3999 Merge remote changes and add evaluation bar to analysis page 2025-12-01 10:30:37 +01:00
Stefan d28914ca35 Add horizontal evaluation bar to analysis page 2025-12-01 10:28:19 +01:00
stefan-kp e5b12ceec1 Add Polish UI language support 2025-12-01 09:52:05 +01:00
Stefan 0e678e0187 analysis 2025-11-29 10:18:23 +01:00
stefan-kp 4102135acd Add play-from-position flow 2025-11-29 08:50:44 +01:00
Stefan 3e8c16b9c2 analysis 2025-11-27 21:23:54 +01:00
Stefan 502f7e28ea docs: Add debug mode documentation to README
Added comprehensive documentation for the debug mode feature including:
- Environment variable configuration (NEXT_PUBLIC_DEBUG)
- What debug mode shows (prompts, responses, timestamps)
- How to use the debug panel (copy, clear, expand)
- Why it's useful (troubleshooting, learning, bug reports)
- Example use cases (verify positions, check evaluations, etc.)
- Warning about production usage

This helps users understand how to enable and use debug mode to
troubleshoot AI behavior and understand how the system works.
2025-11-27 20:47:16 +01:00
Stefan d694ce81ed fix: Display mate scores correctly in move exchange analysis
When Stockfish detects a forced mate, it sets the mate field and resets
the score to 0. The previous code was showing '0 cp' which was misleading.

Changes:
- Format evaluation strings to show 'Mate in X' when mate is detected
- Only show delta (centipawn change) when neither position has a mate
- Update eval instruction to specifically mention mate situations
- Add explanation of mate notation in the prompt

Example output now:
- Pre-Eval: -326 cp
- Post-Eval: Mate in 3
(instead of showing '0 cp' which was confusing)
2025-11-27 20:40:45 +01:00
Stefan 6c215cb3c4 fix: Correctly generate FEN positions before/after moves in move exchange
The previous implementation tried to use undo() on a Chess object created from
a FEN string, which has no move history. This resulted in all three FEN positions
being identical.

Now we use the game object's PGN (which contains full move history) and load it
into temporary Chess objects before undoing moves. This correctly generates:
- FEN before user's move (undo both computer and user moves)
- FEN after user's move (undo only computer move)
- FEN after computer's reply (current position)

This ensures the LLM receives accurate position context for each stage of the
move exchange.
2025-11-27 20:37:43 +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 411b072e2e fix: Add FEN context to move exchange analysis prompt
- Include FEN before user's move, after user's move, and current position
- Ensures LLM has complete position context to understand piece locations
- Fixes issue where LLM could 'forget where pieces are' during move analysis
- Add instruction to use FEN data for piece location understanding
2025-11-27 20:06:21 +01:00
Stefan cbfb6eaa30 docs: Add .env.example with debug mode documentation 2025-11-27 18:21:00 +01:00
Stefan c319904f00 feat: Add debug mode to inspect LLM prompts and responses
- Add DebugContext to track all LLM interactions
- Create DebugPanel component with floating UI
- Track prompts/responses in Tutor component (move analysis, hints, questions)
- Track prompts/responses in Analysis page (move commentary)
- Add NEXT_PUBLIC_DEBUG environment variable to enable/disable
- Include metadata (FEN, personality, language, etc.) in debug entries
- Add copy-to-clipboard and clear functionality
- Add DEBUG_MODE.md documentation
2025-11-27 18:20:12 +01:00
Stefan 54d92eaae5 fix: Update analysis page tests to use aria-labels
- Change from getByText to getByLabelText for navigation buttons
- Buttons now use icon-only display with aria-labels for accessibility
- Fixes tests after UI simplification in previous commit
2025-11-27 12:54:52 +01:00
Stefan 6b50eba05f feat: Add back button and simplify navigation on analysis page
- Import ArrowLeft icon and useRouter from Next.js
- Add back button below header that navigates to home (/)
- Simplify Previous/Next buttons to show only chevron icons
- Remove text labels from navigation buttons for cleaner UI
- Add aria-labels for accessibility
- Consistent with play page navigation pattern
2025-11-27 12:40:21 +01:00
Stefan d3fea58e8e feat: Update analysis page to use multiple opening detection
- Import lookupPossibleOpenings and buildMoveSequenceFromSteps
- Build move sequence from steps array up to currentIndex
- Lookup up to 5 possible openings per position
- Update prompt to include all possible openings
- Update UI to show single opening name or count of possibilities
- Consistent with play page opening detection
2025-11-27 12:38:31 +01:00
Stefan aa389613cb feat: Add chat session to analysis page
- Import ChatSession from @google/generative-ai
- Add chatSession state to maintain conversation history
- Initialize chat session with personality and language context
- Replace stateless generateContent() with chatSession.sendMessage()
- Add FEN before/after to move analysis prompts
- Chat history is preserved when navigating between moves
- LLM can now provide context-aware commentary across the game
2025-11-27 12:36:40 +01:00
Stefan a9a5366832 feat: Update play page to use multiple opening detection
- Change openingData from single to array in ChessGame.tsx
- Update all opening lookups to use lookupPossibleOpenings()
- Extract move sequence from PGN for opening lookup
- Update Tutor.tsx to accept array of openings
- Add smart opening instructions based on count:
  - 1 opening: Confident identification with metadata
  - Multiple: List possibilities, suggest general principles
  - None: Focus on position without inventing names
- Pass up to 5 possible openings to LLM in all prompts
2025-11-27 12:32:59 +01:00