Skip to content

Commit 5dab686

Browse files
authored
Merge branch 'main' into chore/docstring-updates
2 parents 27cd17b + d616501 commit 5dab686

File tree

157 files changed

+14340
-10079
lines changed

Some content is hidden

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

157 files changed

+14340
-10079
lines changed

.claude/rules/architecture.md

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
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
68
├── cli_cmds/ # Command handling, console output (Rich)
9+
│ ├── cmd_init.py # Init orchestrator + Python-specific setup
10+
│ ├── init_config.py # Config types, validation, writing, shared UI helpers
11+
│ ├── init_auth.py # API key management + GitHub app installation
12+
│ ├── github_workflow.py # GitHub Actions workflow generation
13+
│ ├── init_javascript.py # JavaScript/TypeScript project initialization
14+
│ └── oauth_handler.py # OAuth PKCE flow for CodeFlash authentication
715
├── discovery/ # Find optimizable functions
816
├── optimization/ # Generate optimized code via AI
9-
│ ├── optimizer.py # Main optimization orchestration
10-
│ └── function_optimizer.py # Per-function optimization logic
17+
│ └── optimizer.py # Main optimization orchestration
1118
├── verification/ # Run deterministic tests (pytest plugin)
1219
├── benchmarking/ # Performance measurement
1320
├── github/ # PR creation
1421
├── api/ # AI service communication
1522
├── code_utils/ # Code parsing, git utilities
1623
├── models/ # Pydantic models and types
17-
├── languages/ # Multi-language support (Python, JavaScript/TypeScript)
24+
├── languages/ # Multi-language support (Python, JavaScript/TypeScript, Java planned)
25+
│ ├── base.py # LanguageSupport protocol and shared data types
26+
│ ├── registry.py # Language registration and lookup by extension/enum
27+
│ ├── current.py # Current language singleton (set_current_language / current_language_support)
28+
│ ├── function_optimizer.py # FunctionOptimizer base class for per-function optimization
29+
│ ├── code_replacer.py # Language-agnostic code replacement
30+
│ ├── python/
31+
│ │ ├── support.py # PythonSupport (LanguageSupport implementation)
32+
│ │ ├── function_optimizer.py # PythonFunctionOptimizer subclass
33+
│ │ ├── optimizer.py # Python module preparation & AST resolution
34+
│ │ ├── normalizer.py # Python code normalization for deduplication
35+
│ │ ├── test_runner.py # Test subprocess execution for Python
36+
│ │ ├── instrument_codeflash_capture.py # Instrument __init__ with capture decorators
37+
│ │ └── parse_line_profile_test_output.py # Parse line profiler output
38+
│ └── javascript/
39+
│ ├── support.py # JavaScriptSupport (LanguageSupport implementation)
40+
│ ├── function_optimizer.py # JavaScriptFunctionOptimizer subclass
41+
│ ├── optimizer.py # JS project root finding & module preparation
42+
│ └── normalizer.py # JS/TS code normalization for deduplication
1843
├── setup/ # Config schema, auto-detection, first-run experience
1944
├── picklepatch/ # Serialization/deserialization utilities
2045
├── tracing/ # Function call tracing
@@ -30,12 +55,38 @@ codeflash/
3055

3156
| Task | Start here |
3257
|------|------------|
33-
| CLI arguments & commands | `cli_cmds/cli.py` |
58+
| CLI arguments & commands | `cli_cmds/cli.py` (parsing), `main.py` (subcommand dispatch) |
3459
| Optimization orchestration | `optimization/optimizer.py``run()` |
35-
| Per-function optimization | `optimization/function_optimizer.py` |
60+
| Per-function optimization | `languages/function_optimizer.py` (base), `languages/python/function_optimizer.py`, `languages/javascript/function_optimizer.py` |
3661
| Function discovery | `discovery/functions_to_optimize.py` |
3762
| Context extraction | `languages/<lang>/context/code_context_extractor.py` |
38-
| Test execution | `verification/test_runner.py`, `verification/pytest_plugin.py` |
63+
| Test execution | `languages/<lang>/support.py` (`run_behavioral_tests`, etc.), `verification/pytest_plugin.py` |
3964
| Performance ranking | `benchmarking/function_ranker.py` |
4065
| Domain types | `models/models.py`, `models/function_types.py` |
4166
| Result handling | `either.py` (`Result`, `Success`, `Failure`, `is_successful`) |
67+
68+
## LanguageSupport Protocol Methods
69+
70+
Core protocol in `languages/base.py`. Each language (`PythonSupport`, `JavaScriptSupport`) implements these.
71+
72+
| Category | Method/Property | Purpose |
73+
|----------|----------------|---------|
74+
| Identity | `language`, `file_extensions`, `default_file_extension` | Language identification |
75+
| Identity | `comment_prefix`, `dir_excludes` | Language conventions |
76+
| AI service | `default_language_version` | Language version for API payloads (`None` for Python, `"ES2022"` for JS) |
77+
| AI service | `valid_test_frameworks` | Allowed test frameworks for validation |
78+
| Discovery | `discover_functions`, `discover_tests` | Find optimizable functions and their tests |
79+
| Discovery | `adjust_test_config_for_discovery` | Pre-discovery config adjustment (no-op default) |
80+
| Context | `extract_code_context`, `find_helper_functions`, `find_references` | Code dependency extraction |
81+
| Transform | `replace_function`, `format_code`, `normalize_code` | Code modification |
82+
| Validation | `validate_syntax` | Syntax checking |
83+
| Test execution | `run_behavioral_tests`, `run_benchmarking_tests`, `run_line_profile_tests` | Test runners |
84+
| Test results | `test_result_serialization_format` | `"pickle"` (Python) or `"json"` (JS) |
85+
| Test results | `load_coverage` | Load coverage from language-specific format |
86+
| Test results | `compare_test_results` | Equivalence checking between original and candidate |
87+
| Test gen | `postprocess_generated_tests` | Post-process `GeneratedTestsList` objects |
88+
| Test gen | `process_generated_test_strings` | Instrument/transform raw generated test strings |
89+
| Module | `detect_module_system` | Detect project module system (`None` for Python, `"esm"`/`"commonjs"` for JS) |
90+
| Module | `prepare_module` | Parse/validate module before optimization |
91+
| Setup | `setup_test_config` | One-time project setup after language detection |
92+
| Optimizer | `function_optimizer_class` | Return `FunctionOptimizer` subclass for this language |

.claude/rules/code-style.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
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.
12+
- **Pre-commit**: Run `uv run prek` before committing — fix any issues before creating the commit
13+
- **Pre-push**: Before pushing, run `uv run prek run --from-ref origin/<base>` to check all changed files against the PR base — this matches CI behavior and catches issues that per-commit prek misses. To detect the base branch: `gh pr view --json baseRefName -q .baseRefName 2>/dev/null || echo main`

.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

0 commit comments

Comments
 (0)