ee94fcfa96
5 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b40465ca8a |
CLAUDE: Add terminal client commands for manual outcome testing
New Commands:
- manual_outcome <outcome> [location] - Validates ManualOutcomeSubmission
- Tests outcome and location validation
- Shows which outcomes require hit location
- Displays clear validation errors
- test_location <outcome> [handedness] [count] - Tests hit location distribution
- Generates sample hit locations for an outcome
- Shows distribution table with percentages
- Validates pull rates (45% pull, 35% center, 20% opposite)
- Supports both LHB and RHB
Implementation:
- Added validate_manual_outcome() to GameCommands class
- Added test_hit_location() to GameCommands class
- Added do_manual_outcome() to REPL
- Added do_test_location() to REPL
- Uses ManualOutcomeSubmission model from Task 3
- Uses calculate_hit_location() helper from Task 3
Testing:
- Tested manual_outcome with valid outcomes (groundball_c SS, strikeout)
- Tested manual_outcome with invalid outcome (proper error display)
- Tested test_location with groundball_c for RHB (shows distribution)
- All validation and display working correctly
Note: Full play resolution integration deferred to Week 7 Task 6 (WebSocket handlers).
These commands validate and test the new models but don't resolve plays yet.
Files Modified:
- terminal_client/commands.py (+117 lines)
- terminal_client/repl.py (+65 lines)
|
||
|
|
d7caa75310 |
CLAUDE: Add manual outcome testing to terminal client and Phase 3 planning
Terminal Client Enhancements: - Added list_outcomes command to display all PlayOutcome values - Added resolve_with <outcome> command for testing specific scenarios - TAB completion for all outcome names - Full help documentation and examples - Infrastructure ready for Week 7 integration Files Modified: - terminal_client/commands.py - list_outcomes() and forced outcome support - terminal_client/repl.py - do_list_outcomes() and do_resolve_with() commands - terminal_client/completions.py - VALID_OUTCOMES and complete_resolve_with() - terminal_client/help_text.py - Help entries for new commands Phase 3 Planning: - Created comprehensive Week 7 implementation plan (25 pages) - 6 major tasks covering strategic decisions and result charts - Updated 00-index.md to mark Week 6 as 100% complete - Documented manual outcome testing feature Week 6: 100% Complete ✅ Phase 3 Week 7: Ready to begin 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|
|
1c32787195 |
CLAUDE: Refactor game models and modularize terminal client
This commit includes cleanup from model refactoring and terminal client
modularization for better code organization and maintainability.
## Game Models Refactor
**Removed RunnerState class:**
- Eliminated separate RunnerState model (was redundant)
- Replaced runners: List[RunnerState] with direct base references:
- on_first: Optional[LineupPlayerState]
- on_second: Optional[LineupPlayerState]
- on_third: Optional[LineupPlayerState]
- Updated helper methods:
- get_runner_at_base() now returns LineupPlayerState directly
- get_all_runners() returns List[Tuple[int, LineupPlayerState]]
- is_runner_on_X() simplified to direct None checks
**Benefits:**
- Matches database structure (plays table has on_first_id, etc.)
- Simpler state management (direct references vs list management)
- Better type safety (LineupPlayerState vs generic runner)
- Easier to work with in game engine logic
**Updated files:**
- app/models/game_models.py - Removed RunnerState, updated GameState
- app/core/play_resolver.py - Use get_all_runners() instead of state.runners
- app/core/validators.py - Updated runner access patterns
- tests/unit/models/test_game_models.py - Updated test assertions
- tests/unit/core/test_play_resolver.py - Updated test data
- tests/unit/core/test_validators.py - Updated test data
## Terminal Client Refactor
**Modularization (DRY principle):**
Created separate modules for better code organization:
1. **terminal_client/commands.py** (10,243 bytes)
- Shared command functions for game operations
- Used by both CLI (main.py) and REPL (repl.py)
- Functions: submit_defensive_decision, submit_offensive_decision,
resolve_play, quick_play_sequence
- Single source of truth for command logic
2. **terminal_client/arg_parser.py** (7,280 bytes)
- Centralized argument parsing and validation
- Handles defensive/offensive decision arguments
- Validates formats (alignment, depths, hold runners, steal attempts)
3. **terminal_client/completions.py** (10,357 bytes)
- TAB completion support for REPL mode
- Command completions, option completions, dynamic completions
- Game ID completions, defensive/offensive option suggestions
4. **terminal_client/help_text.py** (10,839 bytes)
- Centralized help text and command documentation
- Detailed command descriptions
- Usage examples for all commands
**Updated main modules:**
- terminal_client/main.py - Simplified by using shared commands module
- terminal_client/repl.py - Cleaner with shared functions and completions
**Benefits:**
- DRY: Behavior consistent between CLI and REPL modes
- Maintainability: Changes in one place affect both interfaces
- Testability: Can test commands module independently
- Organization: Clear separation of concerns
## Documentation
**New files:**
- app/models/visual_model_relationships.md
- Visual documentation of model relationships
- Helps understand data flow between models
- terminal_client/update_docs/ (6 phase documentation files)
- Phased documentation for terminal client evolution
- Historical context for implementation decisions
## Tests
**New test files:**
- tests/unit/terminal_client/__init__.py
- tests/unit/terminal_client/test_arg_parser.py
- tests/unit/terminal_client/test_commands.py
- tests/unit/terminal_client/test_completions.py
- tests/unit/terminal_client/test_help_text.py
**Updated tests:**
- Integration tests updated for new runner model
- Unit tests updated for model changes
- All tests passing with new structure
## Summary
- ✅ Simplified game state model (removed RunnerState)
- ✅ Better alignment with database structure
- ✅ Modularized terminal client (DRY principle)
- ✅ Shared command logic between CLI and REPL
- ✅ Comprehensive test coverage
- ✅ Improved documentation
Total changes: 26 files modified/created
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
||
|
|
05fc037f2b |
CLAUDE: Fix game recovery and add required field validation for plays
Fixed critical bugs in game recovery and play persistence: 1. Terminal REPL Auto-Recovery: - Added _ensure_game_loaded() helper to auto-recover games from database - Calls state_manager.recover_game() when game not in memory - Calls _prepare_next_play() after recovery to populate snapshot fields - Enables seamless continuation of games across REPL sessions 2. Play Validation: - Added verification in _save_play_to_db() for required fields - Ensures batter_id, pitcher_id, catcher_id are never NULL - Raises ValueError with clear error message if fields missing - Prevents database constraint violations 3. Updated Commands: - All REPL commands now call _ensure_game_loaded() - Commands: defensive, offensive, resolve, status, quick_play, box_score - Fixes "Game state not found" errors on recovered games Root Cause: - state_manager.recover_game() rebuilds GameState from database - But didn't populate snapshot fields (current_batter_lineup_id, etc.) - _save_play_to_db() requires these fields to save plays - Solution: Call _prepare_next_play() after recovery Files Modified: - app/core/game_engine.py - Added verification in _save_play_to_db() - terminal_client/repl.py - Added _ensure_game_loaded() and integrated Testing: Successfully recovered game, submitted decisions, and resolved plays 🚀 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|
|
918beadf24 |
CLAUDE: Add interactive terminal client for game engine testing
Created comprehensive terminal testing tool with two modes: 1. Interactive REPL (recommended) - Persistent in-memory state 2. Standalone CLI commands - Config file persistence Features: - Interactive REPL using Python cmd module - Persistent event loop prevents DB connection issues - 11 commands for full game control (new_game, defensive, offensive, resolve, etc.) - Beautiful Rich formatting with colors and panels - Auto-generated test lineups for rapid testing - Direct GameEngine access (no WebSocket overhead) - Config file (~/.terminal_client_config.json) for state persistence Files added: - terminal_client/repl.py (525 lines) - Interactive REPL - terminal_client/main.py (516 lines) - Click standalone commands - terminal_client/display.py (218 lines) - Rich formatting - terminal_client/config.py (89 lines) - Persistent config - terminal_client/__main__.py - Dual mode entry point - terminal_client/CLAUDE.md (725 lines) - Full documentation Updated: - backend/CLAUDE.md - Added terminal client to testing section - requirements.txt - Added rich==13.9.4 Perfect for rapid iteration on game engine without building frontend! 🚀 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> |