codeflash-internal/tiles/codeflash-internal-rules/rules/multi-language-handlers.md
Kevin Turcios dfc56f19a0 feat: add Tessl tiles for codeflash-internal (rules, docs, skills)
Three private tiles published to the codeflash workspace:
- codeflash-internal-rules: 6 eager rules (code-style, architecture,
  optimization-patterns, git-conventions, testing-rules, multi-language-handlers)
- codeflash-internal-docs: 8 lazy doc pages (domain-types, optimization-pipeline,
  test-generation-pipeline, context-extraction, aiservice/cf-api endpoints,
  configuration-thresholds, llm-provider-abstraction)
- codeflash-internal-skills: 4 on-demand skills (debug-optimization-failure,
  add-language-support, add-api-endpoint, debug-test-generation)
2026-02-14 22:16:33 -05:00

1.5 KiB

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