Complete modular refactoring of taletorrent game engine: ## Core Architecture Changes - Split monolithic main.py (343 lines) into 6 focused modules - Implement offensive error propagation with context wrapping - Add JSON configuration system with default prompts and settings - Modernize type hints and validation ## New Modules - errors.py: Custom exceptions (GameError, AIError, ConfigError, etc.) with wrap_error() - models.py: Data classes (World, Character, Turn, Item) with validation - config.py: JSON configuration management with defaults and validation - prompts.py: Template-based prompt management extracted from code - ai_client.py: OpenAI wrapper with retry logic and error propagation - game_engine.py: Core game logic with explicit dependency injection ## Key Features - Error propagation: API errors → 'Failed to reach provider: 403' → 'Failed to generate DM turn: ...' - Configuration over code: All prompts moved to JSON config files - Retry logic: Exponential backoff for API failures - Input validation: Strict validation for all public functions - Logging: Optional stderr logging with --enable-logging flag - Modern Python: list[str], str | None syntax, immutable returns ## CLI Enhancements - play command: Interactive game loop with character creation - validate-config: Configuration validation command - info command: Shows both API and game configuration - Interactive setup wizard for API credentials ## Breaking Changes - Removed main.py (no backward compatibility) - Function signatures changed to use explicit dependencies - BSM renamed to bsm (Python naming convention) - All prompts now configurable via JSON files ## Testing - All imports work correctly - CLI commands functional (config, info, validate-config, play) - Configuration file creation and validation working - Ruff linting passes with auto-fixes - Type checking shows warnings but no critical errors This refactoring transforms the codebase from a monolithic structure to a modular, maintainable architecture ready for extension and code review.
taletorrent
Languages
Python
100%