The exec() function was using empty globals dict which prevented list
comprehensions from accessing variables in the local scope. Changed to
use the same dict for both globals and locals to properly support
comprehensions in processing scripts.
Fixes battleship game flow tests that use list comprehensions.
Removed "attempts > 0" check in research/guarded_ai.py that prevented
hints from showing on the first attempt. Matches the fix made to
activity.py for consistent behavior across web app and CLI simulator.
SPEC.yaml fixes:
- Comment out orphaned example code blocks that broke YAML parsing
- Convert progressive hints and dynamic question examples to comments
- Add placeholder keys to maintain valid YAML structure
- All examples now documented but non-executable (reference only)
- Validates with 0 errors
guarded_ai.py refactor (CLI simulator now uses v2.0 features):
- Import activity_utils.py for consistency with activity.py
- Use check_conditions() for advanced metadata conditions (gte, lt, contains, etc.)
- Use filter_content_blocks() for template rendering and conditional blocks
- Use render_template() for dynamic question text with {{variables}}
- Use resolve_conditional_navigation() for if/elif/else navigation
- Use select_weighted_random() for weighted random selection
- Use get_progressive_hint() for progressive hints system
- Create template contexts with built-in variables (current_attempt, etc.)
Benefits:
- Single source of truth for v2.0 logic (activity_utils.py)
- CLI simulator now tests all v2.0 features
- Maintainability: changes to features only need updates in one place
- Consistency: web app and CLI behave identically
All changes validated and tested.
Random Bucket System:
- Probabilistic events that trigger alongside user responses
- Random rolls before categorization to prevent AI bias
- Multiple random events can trigger simultaneously
- User bucket processed first, random events layer on top
- Metadata accumulates across all transitions
- Last transition's navigation wins
Implementation:
- activity.py: Core random bucket rolling logic
- activity_yaml_validator.py: Validation for random_buckets config
- research/guarded_ai.py: CLI simulator with random event display
- tests/unit/test_random_buckets.py: 22 comprehensive tests (all passing)
Fashion Empire Enhancement:
- activity40-fashion-empire-backrooms.yaml: Added random events to 4 zones
- fashion_emergency (5%): Urgent crises testing leadership
- creative_opportunity (10%): Breakthroughs rewarding innovation
- surprise_client (5%): VIP visitors recognizing reputation
- Random events enhance gameplay without hijacking user intent
Documentation:
- research/SPEC.yaml: Complete YAML specification with verbose comments
- All metadata operations (string concat, numeric ops, random)
- Random buckets with flow explanation
- Feedback prompts (multi-agent system)
- Processing scripts (pre_script, processing_script)
- Model overrides (classifier_model, feedback_model)
- Termination patterns and best practices
- Validation rules and examples
New Activities:
- activity-nuclear-power-plant-ai.yaml: Nuclear reactor control simulation
- activity-submarine-simulation.yaml: Deep sea exploration
- activity-unwaste-factory.yaml: Recycling facility management
Testing:
✅ All 22 random bucket tests passing
✅ YAML validation passing for all activities
✅ Deterministic triple-trigger test (100% probability)
When MODEL_X references (MODEL_0, MODEL_1, etc.) are used, the code now
properly looks up actual model names from the dynamic registry (MODEL_CLIENT_MAP)
instead of hardcoding "model" or requiring MODEL_NAME_X environment variables.
Changes:
- app.py: Look up models from MODEL_CLIENT_MAP for the specified endpoint
- guarded_ai.py: Query endpoints for actual model names at initialization
- guarded_ai.py: Use dynamic registry for MODEL_X lookups
This fixes the "model not found" error when using activities with MODEL_X
references like activity37.
Critical fix for guarded_ai.py:
- Add MODEL_NAME_{n} environment variable support
- Fixes hard-coded "model" string that breaks Azure OpenAI and other endpoints
- Falls back to "model" if MODEL_NAME_{n} not specified
- Some endpoints require actual deployment name in model parameter
Validator improvement:
- Allow feedback_prompts as alternative to feedback_tokens_for_ai
- Prevents false warning when using metadata_feedback_filter with new prompt system
Documentation:
- Added MODEL_NAME_{n} examples to CLAUDE.md
- Documented that Azure and similar endpoints need this variable
All 8 activities validated: 0 errors, 0 warnings
Changes:
- Enhanced get_openai_client_and_model() to support MODEL_X references
- Added model parameter (default "MODEL_1") to all AI functions:
- categorize_response()
- generate_ai_feedback()
- provide_feedback()
- provide_feedback_prompts()
- translate_text()
- Updated simulate_activity() to:
- Read classifier_model and feedback_model from YAML
- Support step-level model overrides
- Pass appropriate models to classifier vs feedback functions
This ensures the CLI simulation tool matches the production activity.py behavior.
Major improvements to battleship game feedback accuracy and user experience:
## New Multi-Prompt Feedback System
- Replaced single feedback with 3 specialized prompts: Shot Report, Ship Status, Game Over
- Each prompt has individual metadata filtering to see only relevant data
- Shot Report only sees hit/miss data, Ship Status only sees ship destruction data
- Added STFU token system to suppress empty messages (filtered out automatically)
## Technical Implementation
- Added per-prompt metadata_filter support in YAML structure
- Updated app.py and guarded_ai.py to handle prompt-specific filtering
- Legacy single-prompt system still works with transition-level filtering
- Added comprehensive test suite for feedback system validation
## User Experience Fixes
- Fixed TTS queue blocking JavaScript execution (async promises instead of await)
- Ship Status now correctly reports who destroyed which ship (role confusion fixed)
- Game Over only appears when game actually ends (no more random messages)
- Maintained dramatic storytelling while ensuring factual accuracy
## Battleship-Specific Improvements
- Ship destruction messages only appear when ships actually sink
- Clear separation of concerns: hits/misses vs ship destruction vs game over
- Eliminated false positive ship destruction reports
- Fixed role reversal where wrong player got credit for destruction
The battleship narrator now provides accurate, contextual feedback while preserving the dramatic naval warfare atmosphere.
new field in the transitions is next_section_and_step which is optional
and defaults to None but also can be "section_3:step_1"
modified: app.py
new file: research/activity0.yaml
new file: research/activity13-choose-adventure.yaml
modified: research/guarded_ai.py
new file: research/activity.yaml
new file: research/activity10.yaml
new file: research/activity11.yaml
new file: research/activity12.yaml
new file: research/activity2.yaml
new file: research/activity3.yaml
new file: research/activity4.yaml
new file: research/activity5.yaml
new file: research/activity6.yaml
new file: research/activity7.yaml
new file: research/activity8.yaml
new file: research/activity9.yaml
new file: research/guarded_ai.py