Skip to content

Commit 341c622

Browse files
committed
docs: update rules and architecture for new language structure
- Add JS optimizer, normalizer, and support files to architecture tree - Update key entry points table for per-function optimization and test execution - Add protocol dispatch preference to language-patterns rules - Fix stale context path in optimization-patterns - Add explicit utf-8 encoding rule scoped to new/changed code
1 parent 04a94f2 commit 341c622

6 files changed

Lines changed: 23 additions & 524 deletions

File tree

.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/normalizers/javascript.py

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

0 commit comments

Comments
 (0)