|
1 | 1 | # CLAUDE.md |
2 | 2 |
|
3 | | -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
4 | | - |
5 | 3 | ## Project Overview |
6 | 4 |
|
7 | 5 | CodeFlash is an AI-powered Python code optimizer that automatically improves code performance while maintaining correctness. It uses LLMs to generate optimization candidates, verifies correctness through test execution, and benchmarks performance improvements. |
8 | 6 |
|
9 | | -## Common Commands |
10 | | - |
11 | | -```bash |
12 | | -# Package management (NEVER use pip) |
13 | | -uv sync # Install dependencies |
14 | | -uv sync --group dev # Install dev dependencies |
15 | | -uv add <package> # Add a package |
16 | | - |
17 | | -# Running tests |
18 | | -uv run pytest tests/ # Run all tests |
19 | | -uv run pytest tests/test_foo.py # Run specific test file |
20 | | -uv run pytest tests/test_foo.py::test_bar -v # Run single test |
21 | | - |
22 | | -# Type checking and linting |
23 | | -uv run mypy codeflash/ # Type check |
24 | | -uv run ruff check codeflash/ # Lint |
25 | | -uv run ruff format codeflash/ # Format |
26 | | - |
27 | | -# Linting (run before committing, checks staged files) |
28 | | -uv run prek run |
29 | | - |
30 | | -# Linting in CI (checks all files changed since main) |
31 | | -uv run prek run --from-ref origin/main |
| 7 | +## Optimization Pipeline |
32 | 8 |
|
33 | | -# Mypy type checking (run on changed files before committing) |
34 | | -uv run mypy --non-interactive --config-file pyproject.toml <changed_files> |
35 | | - |
36 | | -# Running the CLI |
37 | | -uv run codeflash --help |
38 | | -uv run codeflash init # Initialize in a project |
39 | | -uv run codeflash --all # Optimize entire codebase |
| 9 | +``` |
| 10 | +Discovery → Ranking → Context Extraction → Test Gen + Optimization → Baseline → Candidate Evaluation → PR |
40 | 11 | ``` |
41 | 12 |
|
42 | | -## Mypy Type Checking |
| 13 | +1. **Discovery** (`discovery/`): Find optimizable functions across the codebase |
| 14 | +2. **Ranking** (`benchmarking/function_ranker.py`): Rank functions by addressable time using trace data |
| 15 | +3. **Context** (`context/`): Extract code dependencies (read-writable code + read-only imports) |
| 16 | +4. **Optimization** (`optimization/`, `api/`): Generate candidates via AI service, run in parallel with test generation |
| 17 | +5. **Verification** (`verification/`): Run candidates against tests, compare outputs via custom pytest plugin |
| 18 | +6. **Benchmarking** (`benchmarking/`): Measure performance, select best candidate by speedup |
| 19 | +7. **Result** (`result/`, `github/`): Create PR with winning optimization |
43 | 20 |
|
44 | | -When modifying code, fix any mypy type errors in the files you changed. Run mypy on changed files: |
| 21 | +## Domain Glossary |
45 | 22 |
|
46 | | -```bash |
47 | | -uv run mypy --non-interactive --config-file pyproject.toml <changed_files> |
48 | | -``` |
49 | | - |
50 | | -Rules: |
51 | | -- Fix type annotation issues: missing return types, incorrect types, Optional/None unions, import errors for type hints |
52 | | -- Do NOT add `# type: ignore` comments — always fix the root cause |
53 | | -- Do NOT fix type errors that require logic changes, complex generic type rework, or anything that could change runtime behavior |
54 | | -- Files in `mypy_allowlist.txt` are checked in CI — ensure they remain error-free |
| 23 | +- **Optimization candidate**: A generated code variant that might be faster (`OptimizedCandidate`) |
| 24 | +- **Function context**: All code needed for optimization — split into read-writable (modifiable) and read-only (reference) |
| 25 | +- **Addressable time**: Time a function spends that could be optimized (own time + callee time / call count) |
| 26 | +- **Candidate forest**: DAG of candidates where refinements/repairs build on previous candidates |
| 27 | +- **Replay test**: Test generated from recorded benchmark data to reproduce real workloads |
| 28 | +- **Tracer**: Profiling system that records function call trees and timings (`tracing/`, `tracer.py`) |
| 29 | +- **Worktree mode**: Git worktree-based parallel optimization (`--worktree` flag) |
55 | 30 |
|
56 | 31 | <!-- Section below is auto-generated by `tessl install` - do not edit manually --> |
57 | 32 |
|
58 | 33 | # Agent Rules <!-- tessl-managed --> |
59 | 34 |
|
60 | 35 | @.tessl/RULES.md follow the [instructions](.tessl/RULES.md) |
61 | | - |
62 | | -@AGENTS.md |
0 commit comments