mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
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)
1.5 KiB
1.5 KiB
Multi-Language Handlers
Registry Pattern
core/registry.pyprovidesLanguageRegistry— a dict mappinglanguage_id → handler_class- Module-level singleton:
registry = LanguageRegistry() - Decorator registration:
@register_handler("python")on handler classes - Duplicate registration raises
ValueError
Dispatcher
core/dispatcher.pyprovidesget_handler_for_language()andget_handler_for_feature()Featureenum maps feature names to capability flags:TESTGEN,OPTIMIZER,CODE_REPAIR,JIT_REWRITE,OPTIMIZATION_REVIEW,EXPLANATIONSget_handler_for_feature()checkssupports_*attribute before instantiation, raisesHandlerNotImplementedErrorif unsupported
Protocols
core/protocols/defines runtime-checkable protocols:LanguageHandler(base): declareslanguage,supports_*booleansOptimizerProtocol:optimizer_optimize(request, data)TestGenProtocol:testgen_generate(request, data)CodeRepairProtocol:code_repair_repair(user_id, optimization_id, ctx)
Adding a New Language
- Create
core/languages/<lang>/directory - Implement handler class with
@register_handler("<lang>")decorator - Set
supports_*flags for implemented features - Implement protocol methods for each supported feature
- Import the module in
core/languages/__init__.pyso the decorator fires - Add language routing in
core/shared/optimizer_router.pyandcore/shared/testgen_router.py - Add tests in
tests/for the new handler