Skip to content

Commit 1112646

Browse files
committed
docs: add CONTRIBUTING.md
Closes #522 Covers the two audiences the issue calls out: 1. People contributing changes back to Codeflash - development environment setup with uv, the single-command verification via uv run prek, test runner invocation, code-style pointers to .claude/rules/code-style.md, and the branch / commit / PR conventions from .claude/rules/git.md and CLAUDE.md. 2. People using Codeflash in editable mode from a source checkout to optimize their own projects, including the install commands for uv and pip, when editable mode is appropriate vs installing the PyPI package, and a pointer to the README Quick Start for the codeflash init flow.
1 parent ef535b8 commit 1112646

1 file changed

Lines changed: 156 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Contributing to Codeflash
2+
3+
Thanks for your interest in contributing. This guide covers both contributing changes back to Codeflash itself and running Codeflash from this repository in editable mode to optimize your own projects.
4+
5+
## Table of contents
6+
7+
- [Quick links](#quick-links)
8+
- [Ways to contribute](#ways-to-contribute)
9+
- [Development environment](#development-environment)
10+
- [Running tests and checks](#running-tests-and-checks)
11+
- [Code style](#code-style)
12+
- [Branches, commits, and pull requests](#branches-commits-and-pull-requests)
13+
- [Using Codeflash in editable mode](#using-codeflash-in-editable-mode)
14+
- [Reporting bugs and requesting features](#reporting-bugs-and-requesting-features)
15+
- [Security issues](#security-issues)
16+
17+
## Quick links
18+
19+
- Issues: https://github.com/codeflash-ai/codeflash/issues
20+
- Discussions and support: [Discord](https://www.codeflash.ai/discord)
21+
- Documentation: https://docs.codeflash.ai
22+
- Security policy: [`SECURITY.md`](SECURITY.md)
23+
- Project conventions for AI agents and humans alike: [`CLAUDE.md`](CLAUDE.md)
24+
25+
## Ways to contribute
26+
27+
- **Bug reports**: open an issue with a minimal reproducer that fails on `main`.
28+
- **Bug fixes**: follow the bug-fix workflow in [`CLAUDE.md`](CLAUDE.md) - read the code, write a failing test, apply the fix, confirm the test now passes.
29+
- **Features**: open an issue first for anything non-trivial so the approach can be agreed before implementation.
30+
- **Documentation**: the full documentation lives at https://docs.codeflash.ai. Fixes to README, docstrings, and this guide can be submitted as PRs here.
31+
- **Language support**: Codeflash supports Python, JavaScript / TypeScript, and Java today. New language support is a significant effort - please start with an issue.
32+
33+
## Development environment
34+
35+
### Prerequisites
36+
37+
- Python 3.9 or newer
38+
- [`uv`](https://github.com/astral-sh/uv) for dependency management (required - do not use `pip` directly)
39+
- `git`
40+
- For JavaScript end-to-end tests: Node.js and `npm`
41+
- For Java end-to-end tests: a JDK (see `.github/workflows/java-e2e.yaml` for the tested version)
42+
43+
### Setup
44+
45+
Fork the repository, clone your fork, and install the dev dependencies with `uv`:
46+
47+
```bash
48+
git clone https://github.com/<your-username>/codeflash.git
49+
cd codeflash
50+
uv sync
51+
```
52+
53+
`uv sync` installs Codeflash plus the `dev` dependency group (ruff, mypy, ipython, type stubs). The `codeflash` CLI is installed into the virtualenv and can be invoked via `uv run codeflash ...`.
54+
55+
### Optional: point at your fork's upstream
56+
57+
```bash
58+
git remote add upstream https://github.com/codeflash-ai/codeflash.git
59+
git fetch upstream
60+
```
61+
62+
## Running tests and checks
63+
64+
Use `uv run prek` as the single verification command. It runs ruff (lint + format), mypy (strict), and related checks in one pass, matching what CI runs.
65+
66+
```bash
67+
# Check every changed file against the pre-commit hooks locally
68+
uv run prek
69+
70+
# Match CI behavior: check everything changed against the PR base branch
71+
BASE=$(gh pr view --json baseRefName -q .baseRefName 2>/dev/null || echo main)
72+
uv run prek run --from-ref origin/$BASE
73+
```
74+
75+
Run the test suite with pytest via `uv`:
76+
77+
```bash
78+
uv run pytest tests/
79+
```
80+
81+
To run a subset:
82+
83+
```bash
84+
uv run pytest tests/code_utils/ -k "test_something"
85+
```
86+
87+
End-to-end tests live under `code_to_optimize/` and are exercised by CI (`.github/workflows/ci.yaml`, `java-e2e.yaml`). They can be run locally by invoking the scripts referenced from those workflows if you have the relevant runtime installed.
88+
89+
## Code style
90+
91+
The full ruleset is in [`.claude/rules/code-style.md`](.claude/rules/code-style.md). Highlights:
92+
93+
- **Line length**: 120 characters.
94+
- **Python**: 3.9+ syntax. Use type annotations consistent with surrounding code.
95+
- **Package management**: `uv` only. Do not add dependencies with `pip install`.
96+
- **Docstrings**: do not add docstrings to new or changed code unless explicitly requested. The codebase intentionally keeps functions self-documenting through clear naming and type annotations.
97+
- **Naming**: no leading underscores on Python names (`_private` style). Python has no true private functions; use public names.
98+
- **File I/O**: always pass `encoding="utf-8"` to `open()`, `Path.read_text()`, `Path.write_text()`, and similar calls in new or changed code. Windows defaults to `cp1252`, which breaks on non-ASCII content.
99+
- **Paths**: prefer absolute paths internally.
100+
- **Verification**: `uv run prek` is the canonical check. Don't run `ruff`, `mypy`, or `python -c "import ..."` separately; `prek` handles them together.
101+
102+
## Branches, commits, and pull requests
103+
104+
- Create a feature branch off an up-to-date `main`. Never commit directly to `main`.
105+
- Use conventional-commit prefixes: `fix:`, `feat:`, `refactor:`, `docs:`, `test:`, `chore:`. Keep commit messages concise (1-2 sentence body max).
106+
- Keep commits atomic - one logical change per commit.
107+
- PR titles also use the conventional format. The PR body should be short and link any related issues.
108+
- If the change corresponds to a Linear ticket, include `CF-#<number>` in the PR body.
109+
- Run `uv run prek` (or `uv run prek run --from-ref origin/main`) before pushing. CI will block merge if hooks fail.
110+
111+
## Using Codeflash in editable mode
112+
113+
If you want to use Codeflash itself to optimize your own Python projects while developing or testing changes to Codeflash, you can install it in editable mode from this repository.
114+
115+
### Install as an editable dependency
116+
117+
From your target project's directory:
118+
119+
```bash
120+
# Using uv (recommended)
121+
uv add --editable /absolute/path/to/your/codeflash/checkout
122+
123+
# Or, if you use pip inside a virtualenv
124+
pip install -e /absolute/path/to/your/codeflash/checkout
125+
```
126+
127+
From the Codeflash repository root you can also run the CLI directly without installing into the target project:
128+
129+
```bash
130+
cd /absolute/path/to/your/codeflash/checkout
131+
uv run codeflash init # in the target project, cwd matters
132+
uv run codeflash --all # optimize the entire target codebase
133+
uv run codeflash optimize script.py
134+
```
135+
136+
You will still need a Codeflash API key - `uv run codeflash init` walks through key generation and GitHub app setup. See the [Quick Start in the README](README.md#quick-start) for the full flow.
137+
138+
### When to use editable mode
139+
140+
- You are iterating on a Codeflash change and want to dogfood it against a real codebase.
141+
- You need to reproduce a bug your target project hits, with your local patches applied.
142+
- You are developing a new optimization rule, heuristic, or language integration and want end-to-end coverage beyond `tests/`.
143+
144+
For day-to-day optimization of a project you are not hacking on Codeflash itself, install the released package from PyPI (`pip install codeflash` or `uv add codeflash`) instead.
145+
146+
## Reporting bugs and requesting features
147+
148+
Before filing a new issue, please:
149+
150+
1. Search existing [open and closed issues](https://github.com/codeflash-ai/codeflash/issues?q=is%3Aissue) to avoid duplicates.
151+
2. Include the Codeflash version (`codeflash --version`) and Python / uv versions.
152+
3. Include the smallest reproducer you can. For bugs, a failing test that exercises the behavior is ideal.
153+
154+
## Security issues
155+
156+
Do not report suspected security issues in public GitHub issues. See [`SECURITY.md`](SECURITY.md) for the reporting process.

0 commit comments

Comments
 (0)