Skip to content

Commit 6730fdc

Browse files
authored
Merge branch 'main' into feat/behavior-test-as-tool
2 parents 6be5697 + e739649 commit 6730fdc

458 files changed

Lines changed: 116421 additions & 8679 deletions

File tree

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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Architecture
2+
3+
```
4+
codeflash/
5+
├── main.py # CLI entry point
6+
├── cli_cmds/ # Command handling, console output (Rich)
7+
├── discovery/ # Find optimizable functions
8+
├── context/ # Extract code dependencies and imports
9+
├── optimization/ # Generate optimized code via AI
10+
│ ├── optimizer.py # Main optimization orchestration
11+
│ └── function_optimizer.py # Per-function optimization logic
12+
├── verification/ # Run deterministic tests (pytest plugin)
13+
├── benchmarking/ # Performance measurement
14+
├── github/ # PR creation
15+
├── api/ # AI service communication
16+
├── code_utils/ # Code parsing, git utilities
17+
├── models/ # Pydantic models and types
18+
├── languages/ # Multi-language support (Python, JavaScript/TypeScript)
19+
├── setup/ # Config schema, auto-detection, first-run experience
20+
├── picklepatch/ # Serialization/deserialization utilities
21+
├── tracing/ # Function call tracing
22+
├── tracer.py # Root-level tracer entry point for profiling
23+
├── lsp/ # IDE integration (Language Server Protocol)
24+
├── telemetry/ # Sentry, PostHog
25+
├── either.py # Functional Result type for error handling
26+
├── result/ # Result types and handling
27+
└── version.py # Version information
28+
```
29+
30+
## Key Entry Points
31+
32+
| Task | Start here |
33+
|------|------------|
34+
| CLI arguments & commands | `cli_cmds/cli.py` |
35+
| Optimization orchestration | `optimization/optimizer.py``run()` |
36+
| Per-function optimization | `optimization/function_optimizer.py` |
37+
| Function discovery | `discovery/functions_to_optimize.py` |
38+
| Context extraction | `context/code_context_extractor.py` |
39+
| Test execution | `verification/test_runner.py`, `verification/pytest_plugin.py` |
40+
| Performance ranking | `benchmarking/function_ranker.py` |
41+
| Domain types | `models/models.py`, `models/function_types.py` |
42+
| Result handling | `either.py` (`Result`, `Success`, `Failure`, `is_successful`) |

.claude/rules/code-style.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Code Style
2+
3+
- **Line length**: 120 characters
4+
- **Python**: 3.9+ syntax
5+
- **Package management**: Always use `uv`, never `pip`
6+
- **Tooling**: Ruff for linting/formatting, mypy strict mode, prek for pre-commit checks
7+
- **Comments**: Minimal - only explain "why", not "what"
8+
- **Docstrings**: Do not add unless explicitly requested
9+
- **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)

.claude/rules/git.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Git Commits & Pull Requests
2+
3+
- **Always create a new branch from `main` before starting any new work** — never commit directly to `main` or reuse an existing feature branch for unrelated changes
4+
- Use conventional commit format: `fix:`, `feat:`, `refactor:`, `docs:`, `test:`, `chore:`
5+
- Keep commits atomic - one logical change per commit
6+
- Commit message body should be concise (1-2 sentences max)
7+
- PR titles should also use conventional format

.claude/rules/language-patterns.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
paths:
3+
- "codeflash/languages/**/*.py"
4+
---
5+
6+
# Language Support Patterns
7+
8+
- Current language is a module-level singleton in `languages/current.py` — use `set_current_language()` / `current_language()`, never pass language as a parameter through call chains
9+
- Use `get_language_support(identifier)` from `languages/registry.py` to get a `LanguageSupport` instance — never import language classes directly
10+
- New language support classes must use the `@register_language` decorator to register with the extension and language registries
11+
- `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
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
paths:
3+
- "codeflash/optimization/**/*.py"
4+
- "codeflash/verification/**/*.py"
5+
- "codeflash/benchmarking/**/*.py"
6+
- "codeflash/context/**/*.py"
7+
---
8+
9+
# Optimization Pipeline Patterns
10+
11+
- All major operations return `Result[SuccessType, ErrorType]` — construct with `Success(value)` / `Failure(error)`, check with `is_successful()` before calling `unwrap()`
12+
- Code context has token limits (`OPTIMIZATION_CONTEXT_TOKEN_LIMIT`, `TESTGEN_CONTEXT_TOKEN_LIMIT` in `config_consts.py`) — exceeding them rejects the function
13+
- `read_writable_code` can span multiple files; `read_only_context_code` is reference-only
14+
- Code is serialized as markdown code blocks: ` ```language:filepath\ncode\n``` ` (see `CodeStringsMarkdown`)
15+
- Candidates form a forest (DAG): refinements/repairs reference `parent_id` on previous candidates
16+
- Test generation and optimization run concurrently — coordinate through `CandidateEvaluationContext`
17+
- Generated tests are instrumented with `codeflash_capture.py` to record return values and traces

.claude/rules/source-code.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
paths:
3+
- "codeflash/**/*.py"
4+
---
5+
6+
# Source Code Rules
7+
8+
- Use `libcst` for code modification/transformation to preserve formatting. `ast` is acceptable for read-only analysis and parsing.

.claude/rules/testing.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
paths:
3+
- "tests/**"
4+
- "codeflash/**/*test*.py"
5+
---
6+
7+
# Testing Conventions
8+
9+
- Code context extraction and replacement tests must always assert for full string equality, no substring matching.
10+
- Use pytest's `tmp_path` fixture for temp directories (it's a `Path` object).
11+
- Write temp files inside `tmp_path`, never use `NamedTemporaryFile` (causes Windows file contention).
12+
- Always call `.resolve()` on Path objects to ensure absolute paths and resolve symlinks.
13+
- Use `.as_posix()` when converting resolved paths to strings (normalizes to forward slashes).
14+
- Any new feature or bug fix that can be tested automatically must have test cases.
15+
- If changes affect existing test expectations, update the tests accordingly. Tests must always pass after changes.
16+
- The pytest plugin patches `time`, `random`, `uuid`, and `datetime` for deterministic test execution — never assume real randomness or real time in verification tests.
17+
- `conftest.py` uses an autouse fixture that calls `reset_current_language()` — tests always start with Python as the default language.

.claude/skills/fix-mypy.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Fix mypy errors
2+
3+
When modifying code, fix any mypy type errors in the files you changed:
4+
5+
```bash
6+
uv run mypy --non-interactive --config-file pyproject.toml <changed_files>
7+
```
8+
9+
- Fix type annotation issues: missing return types, incorrect types, Optional/None unions, import errors for type hints
10+
- Do NOT add `# type: ignore` comments — always fix the root cause
11+
- Do NOT fix type errors that require logic changes, complex generic type rework, or anything that could change runtime behavior
12+
- Files in `mypy_allowlist.txt` are checked in CI — ensure they remain error-free

.claude/skills/fix-prek.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Fix prek failures
2+
3+
When prek (pre-commit) checks fail:
4+
5+
1. Run `uv run prek run` to see failures (local, checks staged files)
6+
2. In CI, the equivalent is `uv run prek run --from-ref origin/main`
7+
3. prek runs ruff format, ruff check, and mypy on changed files
8+
4. Fix issues in order: formatting → lint → type errors
9+
5. Re-run `uv run prek run` to verify all checks pass

.codex/skills/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Managed by Tessl
2+
tessl:*

0 commit comments

Comments
 (0)