fix-code-review-issues #3

Open
fedir wants to merge 2 commits from fix-code-review-issues into main

2 Commits

Author SHA1 Message Date
1807c7eee1 fix: address all code review issues
- Remove default sampling parameters (temperature, max_tokens)
- Add input validation with max_input_chars limit
- Improve error messages and remove emojis
- Fix arrow/backspace input with get_multiline_input()
- Enhance credential validation to test actual API access
- Update configuration defaults and validation
2026-01-27 11:23:03 +01:00
0b37f329c7 refactor: major overhaul of game engine architecture
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.
2026-01-27 10:12:28 +01:00