# Multi-Language Handlers

## Registry Pattern

- `core/registry.py` provides `LanguageRegistry` — a dict mapping `language_id → handler_class`
- Module-level singleton: `registry = LanguageRegistry()`
- Decorator registration: `@register_handler("python")` on handler classes
- Duplicate registration raises `ValueError`

## Dispatcher

- `core/dispatcher.py` provides `get_handler_for_language()` and `get_handler_for_feature()`
- `Feature` enum maps feature names to capability flags: `TESTGEN`, `OPTIMIZER`, `CODE_REPAIR`, `JIT_REWRITE`, `OPTIMIZATION_REVIEW`, `EXPLANATIONS`
- `get_handler_for_feature()` checks `supports_*` attribute before instantiation, raises `HandlerNotImplementedError` if unsupported

## Protocols

- `core/protocols/` defines runtime-checkable protocols:
  - `LanguageHandler` (base): declares `language`, `supports_*` booleans
  - `OptimizerProtocol`: `optimizer_optimize(request, data)`
  - `TestGenProtocol`: `testgen_generate(request, data)`
  - `CodeRepairProtocol`: `code_repair_repair(user_id, optimization_id, ctx)`

## Adding a New Language

1. Create `core/languages/<lang>/` directory
2. Implement handler class with `@register_handler("<lang>")` decorator
3. Set `supports_*` flags for implemented features
4. Implement protocol methods for each supported feature
5. Import the module in `core/languages/__init__.py` so the decorator fires
6. Add language routing in `core/shared/optimizer_router.py` and `core/shared/testgen_router.py`
7. Add tests in `tests/` for the new handler
