Skip to content

Commit 2e4127a

Browse files
authored
Merge pull request #1708 from codeflash-ai/extract-js-optimizer
refactor: extract JavaScript Optimizer subclass
2 parents 8a75fe1 + 341c622 commit 2e4127a

52 files changed

Lines changed: 1630 additions & 2279 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/rules/architecture.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Architecture
22

3+
When adding, moving, or deleting source files, update this doc to match.
4+
35
```
46
codeflash/
57
├── main.py # CLI entry point
@@ -15,9 +17,20 @@ codeflash/
1517
├── code_utils/ # Code parsing, git utilities
1618
├── models/ # Pydantic models and types
1719
├── languages/ # Multi-language support (Python, JavaScript/TypeScript)
18-
│ └── python/
19-
│ ├── function_optimizer.py # PythonFunctionOptimizer (Python-specific hooks)
20-
│ └── optimizer.py # Python module preparation & AST resolution
20+
│ ├── base.py # LanguageSupport protocol and shared data types
21+
│ ├── registry.py # Language registration and lookup by extension/enum
22+
│ ├── current.py # Current language singleton (set_current_language / current_language_support)
23+
│ ├── code_replacer.py # Language-agnostic code replacement
24+
│ ├── python/
25+
│ │ ├── support.py # PythonSupport (LanguageSupport implementation)
26+
│ │ ├── function_optimizer.py # PythonFunctionOptimizer subclass
27+
│ │ ├── optimizer.py # Python module preparation & AST resolution
28+
│ │ └── normalizer.py # Python code normalization for deduplication
29+
│ └── javascript/
30+
│ ├── support.py # JavaScriptSupport (LanguageSupport implementation)
31+
│ ├── function_optimizer.py # JavaScriptFunctionOptimizer subclass
32+
│ ├── optimizer.py # JS project root finding & module preparation
33+
│ └── normalizer.py # JS/TS code normalization for deduplication
2134
├── setup/ # Config schema, auto-detection, first-run experience
2235
├── picklepatch/ # Serialization/deserialization utilities
2336
├── tracing/ # Function call tracing
@@ -35,10 +48,10 @@ codeflash/
3548
|------|------------|
3649
| CLI arguments & commands | `cli_cmds/cli.py` |
3750
| Optimization orchestration | `optimization/optimizer.py``run()` |
38-
| Per-function optimization | `optimization/function_optimizer.py` (base), `languages/python/function_optimizer.py` (Python subclass) |
51+
| Per-function optimization | `optimization/function_optimizer.py` (base), `languages/python/function_optimizer.py`, `languages/javascript/function_optimizer.py` |
3952
| Function discovery | `discovery/functions_to_optimize.py` |
4053
| Context extraction | `languages/<lang>/context/code_context_extractor.py` |
41-
| Test execution | `verification/test_runner.py`, `verification/pytest_plugin.py` |
54+
| Test execution | `languages/<lang>/support.py` (`run_behavioral_tests`, etc.), `verification/pytest_plugin.py` |
4255
| Performance ranking | `benchmarking/function_ranker.py` |
4356
| Domain types | `models/models.py`, `models/function_types.py` |
4457
| Result handling | `either.py` (`Result`, `Success`, `Failure`, `is_successful`) |

.claude/rules/code-style.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
- **Comments**: Minimal - only explain "why", not "what"
88
- **Docstrings**: Do not add unless explicitly requested
99
- **Naming**: NEVER use leading underscores (`_function_name`) - Python has no true private functions, use public names
10-
- **Paths**: Always use absolute paths, handle encoding explicitly (UTF-8)
10+
- **Paths**: Always use absolute paths
11+
- **Encoding**: Always pass `encoding="utf-8"` to `open()`, `read_text()`, `write_text()`, etc. in new or changed code — Windows defaults to `cp1252` which breaks on non-ASCII content. Don't flag pre-existing code that lacks it unless you're already modifying that line.

.claude/rules/language-patterns.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ paths:
99
- Use `get_language_support(identifier)` from `languages/registry.py` to get a `LanguageSupport` instance — never import language classes directly
1010
- New language support classes must use the `@register_language` decorator to register with the extension and language registries
1111
- `languages/__init__.py` uses `__getattr__` for lazy imports to avoid circular dependencies — follow this pattern when adding new exports
12-
- `is_javascript()` returns `True` for both JavaScript and TypeScript
12+
- Prefer `LanguageSupport` protocol dispatch over `is_python()`/`is_javascript()` guards — remaining guards are being migrated to protocol methods
13+
- `is_javascript()` returns `True` for both JavaScript and TypeScript (still used in ~15 call sites pending migration)

.claude/rules/optimization-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ paths:
33
- "codeflash/optimization/**/*.py"
44
- "codeflash/verification/**/*.py"
55
- "codeflash/benchmarking/**/*.py"
6-
- "codeflash/context/**/*.py"
6+
- "codeflash/languages/*/context/**/*.py"
77
---
88

99
# Optimization Pipeline Patterns

codeflash/code_utils/code_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,10 @@ def get_all_function_names(code: str) -> tuple[bool, list[str]]:
408408
def get_run_tmp_file(file_path: Path | str) -> Path:
409409
if isinstance(file_path, str):
410410
file_path = Path(file_path)
411-
if not hasattr(get_run_tmp_file, "tmpdir"):
411+
if not hasattr(get_run_tmp_file, "tmpdir_path"):
412412
get_run_tmp_file.tmpdir = TemporaryDirectory(prefix="codeflash_")
413-
return Path(get_run_tmp_file.tmpdir.name) / file_path
413+
get_run_tmp_file.tmpdir_path = Path(get_run_tmp_file.tmpdir.name)
414+
return get_run_tmp_file.tmpdir_path / file_path
414415

415416

416417
def path_belongs_to_site_packages(file_path: Path) -> bool:

codeflash/code_utils/config_consts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
MAX_TEST_RUN_ITERATIONS = 5
77
OPTIMIZATION_CONTEXT_TOKEN_LIMIT = 64000
88
TESTGEN_CONTEXT_TOKEN_LIMIT = 64000
9+
READ_WRITABLE_LIMIT_ERROR = "Read-writable code has exceeded token limit, cannot proceed"
10+
TESTGEN_LIMIT_ERROR = "Testgen code context has exceeded token limit, cannot proceed"
911
INDIVIDUAL_TESTCASE_TIMEOUT = 15
1012
MAX_FUNCTION_TEST_SECONDS = 60
1113
MIN_IMPROVEMENT_THRESHOLD = 0.05

codeflash/code_utils/deduplicate_code.py

Lines changed: 0 additions & 126 deletions
This file was deleted.

codeflash/code_utils/normalizers/__init__.py

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)