Skip to content

Commit fb2d8c3

Browse files
authored
Merge branch 'main' into add-oauth-pkce-login
2 parents 9a1e152 + f9e3b83 commit fb2d8c3

11 files changed

Lines changed: 1206 additions & 58 deletions

File tree

.claude-plugin/marketplace.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"email": "support@codeflash.ai"
77
},
88
"metadata": {
9-
"description": "Codeflash plugin for Claude Code — optimize Python code for performance",
9+
"description": "Codeflash plugin for Claude Code — optimize code for performance",
1010
"version": "0.1.10"
1111
},
1212
"plugins": [
1313
{
1414
"name": "codeflash",
15-
"description": "Run codeflash as a background agent to optimize Python code for performance",
15+
"description": "Run codeflash as a background agent to optimize code for performance",
1616
"version": "0.1.10",
1717
"author": {
1818
"name": "Codeflash",
@@ -22,7 +22,7 @@
2222
"homepage": "https://codeflash.ai",
2323
"repository": "https://github.com/codeflash-ai/codeflash-cc-plugin",
2424
"license": "MIT",
25-
"keywords": ["python", "optimization", "performance", "codeflash"],
25+
"keywords": ["python", "javascript", "typescript", "optimization", "performance", "codeflash", "speedup", "runtime"],
2626
"category": "development"
2727
}
2828
]

.claude-plugin/plugin.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "codeflash",
3-
"description": "Run codeflash as a background agent to optimize Python code for performance",
4-
"version": "0.1.11",
3+
"description": "Run codeflash as a background agent to optimize code for performance",
4+
"version": "0.1.10",
55
"author": {
66
"name": "Codeflash",
77
"url": "https://codeflash.ai"
88
},
99
"repository": "https://github.com/codeflash-ai/codeflash-cc-plugin",
1010
"homepage": "https://codeflash.ai",
1111
"license": "MIT",
12-
"keywords": ["python", "optimization", "performance", "codeflash"]
12+
"keywords": ["python", "javascript", "typescript", "optimization", "performance", "codeflash", "speedup", "runtime"]
1313
}

.github/workflows/test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
test:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest]
14+
15+
env:
16+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: actions/setup-node@v4
22+
with:
23+
node-version: "22"
24+
25+
- name: Install BATS
26+
run: npm install -g bats
27+
28+
- name: Verify dependencies
29+
run: |
30+
bats --version
31+
jq --version
32+
git --version
33+
34+
- name: Run tests
35+
run: bats tests/

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Codeflash Claude Code Plugin
22

3-
A minimal Claude Code plugin that runs [Codeflash](https://codeflash.ai) as a background agent to optimize Python code for performance.
3+
A minimal Claude Code plugin that runs [Codeflash](https://codeflash.ai) as a background agent to optimize Python, JavaScript, and TypeScript code for performance.
44

55
## Prerequisites
66

77
- Claude Code v2.1.38 or later
8-
- [codeflash](https://pypi.org/project/codeflash/) installed in your project
9-
- Project initialized with `codeflash init` (creates `[tool.codeflash]` in `pyproject.toml`)
8+
- **Python projects**: [codeflash](https://pypi.org/project/codeflash/) installed in a virtual environment, configured via `[tool.codeflash]` in `pyproject.toml`
9+
- **JS/TS projects**: [codeflash](https://www.npmjs.com/package/codeflash) installed as a dev dependency (`npm install --save-dev codeflash`), configured via a `"codeflash"` key in `package.json`
1010

1111
## Installation
1212

@@ -69,7 +69,7 @@ Run `/plugin` to open the plugin manager and confirm codeflash appears under the
6969

7070
### Auto-suggest after commits
7171

72-
When you make a git commit that includes Python file changes, the plugin suggests running `/optimize` on those files.
72+
When you make a git commit that includes Python, JavaScript, or TypeScript file changes, the plugin suggests running `/optimize` on those files.
7373

7474
## Plugin Structure
7575

@@ -84,7 +84,7 @@ codeflash-cc-plugin/
8484
│ └── hooks.json # Stop hook for commit detection
8585
├── scripts/
8686
│ ├── find-venv.sh # Shared helper: find and activate a Python venv
87-
│ └── suggest-optimize.sh # Detects Python changes, suggests /optimize
87+
│ └── suggest-optimize.sh # Detects Python/JS/TS changes, suggests /optimize
8888
├── skills/
8989
│ └── optimize/
9090
│ └── SKILL.md # /optimize slash command
@@ -96,7 +96,7 @@ codeflash-cc-plugin/
9696
The plugin is a thin wrapper around the `codeflash` CLI:
9797

9898
1. `/optimize` spawns a background optimizer agent
99-
2. Verifies codeflash is installed (via `pip install codeflash`) and configured
99+
2. Verifies codeflash is installed (`pip install codeflash` for Python, `npm install --save-dev codeflash` for JS/TS) and configured
100100
3. Runs the `codeflash` CLI with the appropriate flags
101101
4. Reports results (optimizations found, PRs created)
102102

agents/optimizer.md

Lines changed: 114 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: optimizer
33
description: |
4-
Optimizes Python code for performance using Codeflash. Use when asked to optimize, speed up, or improve performance of Python code. Also triggered automatically after commits that change Python files.
4+
Optimizes Python and JavaScript/TypeScript code for performance using Codeflash. Use when asked to optimize, speed up, or improve performance of Python, JavaScript, or TypeScript code. Also triggered automatically after commits that change Python/JS/TS files.
55
66
<example>
77
Context: User explicitly asks to optimize code
@@ -21,6 +21,24 @@ description: |
2121
</commentary>
2222
</example>
2323
24+
<example>
25+
Context: User explicitly asks to optimize JS/TS code
26+
user: "Optimize src/utils.ts for performance"
27+
assistant: "I'll use the optimizer agent to run codeflash on that file."
28+
<commentary>
29+
Direct optimization request for a TypeScript file — trigger the optimizer agent with the file path.
30+
</commentary>
31+
</example>
32+
33+
<example>
34+
Context: User wants to speed up a JS/TS function
35+
user: "Can you make the parseData function in src/parser.js faster?"
36+
assistant: "I'll use the optimizer agent to optimize that function with codeflash."
37+
<commentary>
38+
Performance improvement request targeting a specific JS function — trigger with file and function name.
39+
</commentary>
40+
</example>
41+
2442
<example>
2543
Context: Hook detected Python files changed in a commit
2644
user: "Python files were changed in the latest commit. Use the Task tool to optimize..."
@@ -36,7 +54,7 @@ color: cyan
3654
tools: Read, Glob, Grep, Bash, Write, Edit
3755
---
3856

39-
You are a thin-wrapper agent that runs the codeflash CLI to optimize Python code.
57+
You are a thin-wrapper agent that runs the codeflash CLI to optimize Python and JavaScript/TypeScript code.
4058

4159
## Workflow
4260

@@ -139,13 +157,24 @@ export CODEFLASH_API_KEY="cf-your-key-here"
139157

140158
### 1. Locate Project Configuration
141159

142-
Walk upward from the current working directory to the git repository root (`git rev-parse --show-toplevel`) looking for `pyproject.toml`. Use the **first** (closest to CWD) file found. Record:
143-
- **Project directory**: the directory containing the discovered `pyproject.toml`
144-
- **Configured**: whether the file contains a `[tool.codeflash]` section
160+
Walk upward from the current working directory to the git repository root (`git rev-parse --show-toplevel`) looking for a project configuration file. Check for both `pyproject.toml` (Python) and `package.json` (JavaScript/TypeScript) at each directory level. Use the **first** (closest to CWD) file found.
161+
162+
**Determine the project type:**
163+
- If `pyproject.toml` is found first → **Python project**. Record:
164+
- **Project directory**: the directory containing `pyproject.toml`
165+
- **Configured**: whether the file contains a `[tool.codeflash]` section
166+
- If `package.json` is found first → **JS/TS project**. Record:
167+
- **Project directory**: the directory containing `package.json`
168+
- **Configured**: whether the JSON has a `"codeflash"` key at the root level
169+
- If both exist in the same directory, determine the project type from the file being optimized (`.py` → Python, `.js`/`.ts`/`.jsx`/`.tsx` → JS/TS). If ambiguous, prefer `pyproject.toml`.
170+
171+
If neither file is found, use the git repository root as the project directory.
145172

146-
If no `pyproject.toml` is found, use the git repository root as the project directory.
173+
### 2. Verify Environment and Installation
147174

148-
### 2. Verify Virtual Environment and Installation
175+
The verification process depends on the project type determined in Step 1.
176+
177+
#### 2a. Python projects
149178

150179
First, check that a Python virtual environment is active by running `echo $VIRTUAL_ENV`.
151180

@@ -182,8 +211,30 @@ pip install codeflash
182211
183212
If the user agrees, run the installation command in the project directory. If installation succeeds, proceed to Step 3. If the user declines or installation fails, stop.
184213

214+
#### 2b. JS/TS projects
215+
216+
Check whether the `codeflash` npm package is installed in the project by running:
217+
218+
```bash
219+
npx codeflash --version
220+
```
221+
222+
If it succeeds, proceed to Step 3.
223+
224+
If it fails (command not found or package not available), codeflash is not installed. Ask the user whether they'd like to install it now:
225+
226+
```bash
227+
npm install --save-dev codeflash
228+
```
229+
230+
If the user agrees, run the installation command in the project directory (from Step 1). If installation succeeds, proceed to Step 3. If the user declines or installation fails, stop.
231+
185232
### 3. Verify Setup
186233

234+
The setup process depends on the project type determined in Step 1.
235+
236+
#### 3a. Python projects (`pyproject.toml`)
237+
187238
Use the `pyproject.toml` discovered in Step 1:
188239

189240
- **If `[tool.codeflash]` is already present** → check the formatter (see sub-step 5 below), then proceed to Step 4.
@@ -213,23 +264,60 @@ formatter-cmds = ["disabled"]
213264

214265
5. **Verify formatter**: Read the `formatter-cmds` value from the `[tool.codeflash]` section. If it is set to `["disabled"]` or is empty, skip this check. Otherwise, for each command in the `formatter-cmds` list, extract the base command name (the first word, e.g. `black` from `"black --line-length 88 {file}"`) and run `which <command>` to check if it is installed. If any formatter command is **not found**, inform the user which formatter(s) are missing and ask if they'd like to install them (e.g. `pip install <formatter>`). If the user agrees, run the install. If the user declines, warn that codeflash may fail to format optimized code and proceed to Step 4 anyway.
215266

267+
#### 3b. JS/TS projects (`package.json`)
268+
269+
Use the `package.json` discovered in Step 1:
270+
271+
- **If a `"codeflash"` key already exists at the root of the JSON** → check the formatter (see sub-step 5 below), then proceed to Step 4.
272+
- **If `package.json` exists but has no `"codeflash"` key** → add the config to that file.
273+
- **If no `package.json` was found** → create one at the git repository root with `npm init -y`, then add the config.
274+
275+
When configuration is missing, interactively set it up:
276+
277+
1. **Ask the user two questions** (use AskUserQuestion or prompt directly):
278+
- **Module root**: "What is the relative path to the root of your JavaScript/TypeScript module?" (e.g. `.` for the root directory, `src`, `src/lib`)
279+
- **Tests folder**: "What is the relative path to your tests folder?" (e.g. `tests`, `test`, `__tests__`, `src/__tests__`)
280+
281+
2. **Validate directories**: Check whether the tests folder the user provided exists. If it does **not** exist, create it with `mkdir -p`.
282+
283+
3. **Write the configuration**: Read the existing `package.json`, parse it as JSON, add a `"codeflash"` key at the root level, and write the file back. Use exactly this structure, substituting the user's answers:
284+
285+
```json
286+
{
287+
"codeflash": {
288+
"moduleRoot": "<user's module root>",
289+
"testsRoot": "<user's tests folder>",
290+
"formatterCmds": ["disabled"],
291+
"ignorePaths": ["dist", "**/node_modules", "**/__tests__"]
292+
}
293+
}
294+
```
295+
296+
**Important**: When writing to `package.json`, you must preserve all existing content. Read the file, parse the JSON, add/update only the `"codeflash"` key, then write the full JSON back with 2-space indentation.
297+
298+
4. Confirm to the user that the configuration has been written.
299+
300+
5. **Verify formatter**: Read the `formatterCmds` value from the `"codeflash"` config. If it is set to `["disabled"]` or is empty, skip this check. Otherwise, for each command in the `formatterCmds` array, extract the base command name (the first word, ignoring `npx` — e.g. `prettier` from `"npx prettier --write {file}"`). If the command is invoked via `npx`, check that the package is available with `npx <command> --version`. If invoked directly, run `which <command>`. If any formatter command is **not found**, inform the user which formatter(s) are missing and ask if they'd like to install them (e.g. `npm install --save-dev <formatter>`). If the user agrees, run the install. If the user declines, warn that codeflash may fail to format optimized code and proceed to Step 4 anyway.
301+
216302
Then proceed to Step 4.
217303

218304
### 4. Parse Task Prompt
219305

220306
Extract from the prompt you receive:
221-
- **file path**: Python file to optimize (e.g. `src/utils.py`)
307+
- **file path**: file to optimize (e.g. `src/utils.py`, `src/utils.ts`)
222308
- **function name**: Specific function to target (optional)
223309
- Any other flags: pass through to codeflash
224310

225311
If no file and no `--all` flag, run codeflash without `--file` or `--all` to let it detect changed files automatically. Only use `--all` when explicitly requested.
226312

227313
### 5. Run Codeflash
228314

229-
If the project directory from Step 1 differs from the current working directory, **`cd` to the project directory first** so that relative paths in the config resolve correctly.
315+
**Always `cd` to the project directory** (from Step 1) before running codeflash, so that relative paths in the config resolve correctly.
230316

231317
Execute the appropriate command **in the background** (`run_in_background: true`) with a **10-minute timeout** (`timeout: 600000`):
232318

319+
#### Python projects
320+
233321
```bash
234322
# Default: let codeflash detect changed files
235323
source $VIRTUAL_ENV/bin/activate && cd <project_dir> && codeflash --subagent [flags]
@@ -243,6 +331,23 @@ source $VIRTUAL_ENV/bin/activate && cd <project_dir> && codeflash --subagent --a
243331

244332
If CWD is already the project directory, omit the `cd`. Always include the `source $VIRTUAL_ENV/bin/activate` prefix to ensure the virtual environment is active in the shell that runs codeflash.
245333

334+
#### JS/TS projects
335+
336+
**Important**: Codeflash must always be run from the project root (the directory containing `package.json`).
337+
338+
```bash
339+
# Default: let codeflash detect changed files
340+
cd <project_dir> && npx codeflash --subagent [flags]
341+
342+
# Specific file
343+
cd <project_dir> && npx codeflash --subagent --file <path> [--function <name>] [flags]
344+
345+
# All files (only when explicitly requested with --all)
346+
cd <project_dir> && npx codeflash --subagent --all [flags]
347+
```
348+
349+
If CWD is already the project directory, omit the `cd`. Use `npx codeflash` (no virtual environment activation needed).
350+
246351
**IMPORTANT**: Always use `run_in_background: true` when calling the Bash tool to execute codeflash. This allows optimization to run in the background while Claude continues other work. Tell the user "Codeflash is optimizing in the background, you'll be notified when it completes" and do not wait for the result.
247352

248353
### 6. Report Initial Status

scripts/find-venv.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Effect: If no venv is active, searches common locations relative to
66
# CHECK_DIR and REPO_ROOT, and activates the first one found.
77
# After return, VIRTUAL_ENV will be set if a venv was found.
8+
#
9+
# Note: This helper is only used for Python projects. JS/TS projects
10+
# do not require a virtual environment — they use npx/npm instead.
811

912
if [ -z "${VIRTUAL_ENV:-}" ]; then
1013
for candidate in "$CHECK_DIR/.venv" "$CHECK_DIR/venv" "$REPO_ROOT/.venv" "$REPO_ROOT/venv"; do

0 commit comments

Comments
 (0)