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.7 KiB
1.7 KiB
Optimization Patterns
Router Dispatch
- Shared routers in
core/shared/dispatch by thelanguagefield on the request schema - Lazy imports inside the endpoint body to avoid circular dependencies:
if data.language in ("javascript", "typescript"): from core.languages.js_ts.optimizer import optimize_javascript # noqa: PLC0415 return await optimize_javascript(request, data) - Default language is Python
Context Extraction
BaseOptimizerContextinoptimizer_context.pyhandles prompt management and code extraction- Two context types:
SingleOptimizerContext(single-file) andMultiOptimizerContext(multi-file) extract_code_and_explanation_from_llm_res()parses LLM markdown response into code blocksparse_and_generate_candidate_schema()converts extracted code toOptimizeResponseItemSchema
Model Distribution
get_model_distribution()inoptimizer_config.pysplits calls between OpenAI and Anthropic- Formula:
claude_calls = (total - 1) // 2,gpt_calls = total - claude_calls MAX_OPTIMIZER_CALLS = 6,MAX_OPTIMIZER_LP_CALLS = 7- Claude gets fewer calls as it's more expensive
Postprocessing
postprocess.pyhandles deduplication and validation of optimization candidates- Deduplication: normalize with
ast.parse()+ast.dump(), skip duplicates with identical AST - Equality check: compare optimized code to original to skip no-ops
- Uses
libcstfor all code transformations (preserves formatting)
Prompt Templates
- Prompts stored as
.mdfiles alongside their modules - Rendered with Jinja2 (e.g.,
build_prompt()in testgen) - System and user prompts are constructed per-context type