fix-code-review-issues #3

Open
fedir wants to merge 2 commits from fix-code-review-issues into main
Owner
No description provided.
fedir added 2 commits 2026-01-27 11:26:38 +01:00
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.
- 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
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix-code-review-issues:fix-code-review-issues
git checkout fix-code-review-issues
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: fedir/taletorrent#3