From 4b5da3558b5f1229909acb9647b55e57ac1d6581 Mon Sep 17 00:00:00 2001 From: Mohamed Ashraf Date: Thu, 2 Apr 2026 11:14:48 +0000 Subject: [PATCH] docs: add Java support to setup skill, optimize skill, and stop hook Co-Authored-By: Claude Opus 4.6 --- scripts/suggest-optimize.sh | 11 +++++++++ skills/optimize/SKILL.md | 7 ++++-- skills/setup/SKILL.md | 48 ++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/scripts/suggest-optimize.sh b/scripts/suggest-optimize.sh index ec7f8b0..44e2022 100755 --- a/scripts/suggest-optimize.sh +++ b/scripts/suggest-optimize.sh @@ -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" @@ -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 diff --git a/skills/optimize/SKILL.md b/skills/optimize/SKILL.md index 3b2a184..10b808b 100644 --- a/skills/optimize/SKILL.md +++ b/skills/optimize/SKILL.md @@ -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 diff --git a/skills/setup/SKILL.md b/skills/setup/SKILL.md index 7631ebc..4ddcac8 100644 --- a/skills/setup/SKILL.md +++ b/skills/setup/SKILL.md @@ -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 `` 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 `` section of `pom.xml`. Only write properties that differ from defaults: + +```xml + + + src/main/java + + src/test/java + +``` + +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