Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions scripts/suggest-optimize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ fi
# Determine which language families actually had changes
HAS_PYTHON_CHANGES="false"
HAS_JS_CHANGES="false"
HAS_JAVA_CHANGES="false"
if echo "$CHANGED_FILES" | grep -qE '\.py$'; then
HAS_PYTHON_CHANGES="true"
fi
if echo "$CHANGED_FILES" | grep -qE '\.(js|ts|jsx|tsx)$'; then
HAS_JS_CHANGES="true"
fi
if echo "$CHANGED_FILES" | grep -qE '\.java$'; then
HAS_JAVA_CHANGES="true"
fi

# Dedup: don't trigger twice for the same set of changes.
SEEN_MARKER="$TRANSCRIPT_DIR/codeflash-seen"
Expand Down Expand Up @@ -130,6 +134,13 @@ if [ "$HAS_JS_CHANGES" = "true" ]; then
exit 0
fi

# --- Java project path ----------------------------------------------------
if [ "$HAS_JAVA_CHANGES" = "true" ]; then
MESSAGE="Java files were changed in a recent commit. Use the codeflash:optimize skill WITHOUT ANY ARGUMENTS to optimize the Java code for performance."
jq -nc --arg reason "$MESSAGE" '{"decision": "block", "reason": $reason, "systemMessage": $reason}'
exit 0
fi

# --- Python project path ---------------------------------------------------
if [ "$HAS_PYTHON_CHANGES" != "true" ]; then
exit 0
Expand Down
7 changes: 5 additions & 2 deletions skills/optimize/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ Disambiguate the file and function from `$ARGUMENTS` if --file and/or --function

## Correct cwd

Based on the language of the file/s of concern, Find the `pyproject.toml` (Python) /`package.json` (JS/TS) file closest to the file/files of concern (the file passed to codeflash --file or the files which changed in the diff).
Based on the language of the file/s of concern, find the config file closest to the file/files of concern (the file passed to codeflash --file or the files which changed in the diff):
- **Python**: `pyproject.toml`
- **JS/TS**: `package.json`
- **Java**: `pom.xml` or `build.gradle`/`build.gradle.kts`

`cd` into the directory where you found the `pyproject.toml`/`package.json`.
`cd` into the directory where you found the config file.

## Build the command

Expand Down
48 changes: 47 additions & 1 deletion skills/setup/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,54 @@ Merge this into the existing `package.json` object — do not overwrite other fi

### Check 1c: Project Configuration (Java)

Find the `pom.xml` (if it's a maven project) or `build.gradle.kts` (if it's a gradle project) file closest to the file/files of concern (the file passed to codeflash --file or the files which changed in the diff).
Find the `pom.xml` (Maven) or `build.gradle`/`build.gradle.kts` (Gradle) file closest to the file/files of concern (the file passed to codeflash --file or the files which changed in the diff).

For Maven projects, check if `codeflash.*` properties exist in the `<properties>` section of `pom.xml`. For Gradle projects, check if `codeflash.*` properties exist in `gradle.properties`.

- If the build file exists but lacks codeflash properties, run **Configuration Discovery (Java)** below and add them.
- If no build file exists, exit early — Java projects require Maven or Gradle.

#### Configuration Discovery (Java)

Perform the following discovery steps relative to the directory containing the target `pom.xml` or `build.gradle`:

**Discover source root:**
Find the relative path to the Java source directory. Look for:
1. Standard Maven/Gradle layout: `src/main/java`
2. Custom `sourceDirectory` in `pom.xml`
3. Fallback to `src` if it exists
Default to `src/main/java`.

**Discover test root:**
Find the relative path to the Java test directory. Look for:
1. Standard layout: `src/test/java`
2. Custom `testSourceDirectory` in `pom.xml`
3. Directories named `test` or `tests`
Default to `src/test/java`.

**Write the configuration:**

For Maven projects, add `codeflash.*` properties to the `<properties>` section of `pom.xml`. Only write properties that differ from defaults:

```xml
<properties>
<!-- Only add if source root is NOT src/main/java -->
<codeflash.moduleRoot>src/main/java</codeflash.moduleRoot>
<!-- Only add if test root is NOT src/test/java -->
<codeflash.testsRoot>src/test/java</codeflash.testsRoot>
</properties>
```

For Gradle projects, add properties to `gradle.properties` (create the file if it doesn't exist):

```properties
codeflash.moduleRoot=src/main/java
codeflash.testsRoot=src/test/java
```

If the project uses the standard `src/main/java` and `src/test/java` layout, no config properties are needed — Codeflash auto-detects the defaults.

After writing, confirm the configuration with the user before proceeding.

### Check 2: Installation

Expand Down
Loading