codeflash-agent/plugin/languages/java/agents/codeflash-java.md
mashraf-222 270cb56cee
Feat/java language support (#12)
* Add Java/Kotlin detection to top-level language router

Adds pom.xml, build.gradle, build.gradle.kts, settings.gradle, and
settings.gradle.kts as markers that route to the codeflash-java router.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add Java/Kotlin agent definitions for all optimization domains

10 agents covering the full optimization pipeline:
- codeflash-java: router/team lead for domain detection
- codeflash-java-setup: environment detection (build tool, JDK, profiling tools)
- codeflash-java-deep: cross-domain optimizer (default)
- codeflash-java-cpu: data structures, algorithms, JIT deopt, JMH benchmarks
- codeflash-java-memory: heap/GC tuning, escape analysis, leak detection
- codeflash-java-async: virtual threads, lock contention, CompletableFuture
- codeflash-java-structure: class loading, JPMS, startup time, circular deps
- codeflash-java-scan: quick cross-domain diagnosis via JFR/jdeps/GC logs
- codeflash-java-ci: GitHub webhook handler for Java PRs
- codeflash-java-pr-prep: JMH benchmarks and PR body templates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add Java domain reference guides for all optimization domains

6 guides covering deep domain knowledge for agent consumption:
- data-structures: collection selection, autoboxing, JIT patterns, sorting
- memory: JVM heap layout, GC algorithms and tuning, escape analysis, leaks
- async: virtual threads, structured concurrency, lock hierarchy, contention
- structure: class loading, JPMS, CDS/AppCDS, ServiceLoader, Spring startup
- database: JPA N+1, HikariCP, pagination, batch operations, EXPLAIN plans
- native: JNI, Panama FFM API, GraalVM native-image, Vector API

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add Java optimization skills: session launcher and JFR profiling

- codeflash-optimize: session launcher with start/resume/status/scan/review
- jfr-profiling: quick-action JFR profiling in cpu/alloc/wall modes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Slim Java agents to match Go's concise ~175-line pattern

Move inline code examples, antipattern encyclopedias, JMH templates,
and deep-dive sections from agent prompts into reference guides.
Agents now contain only: target tables, one-liner antipatterns,
reasoning checklists, profiling commands, and keep/discard trees.

Line counts (before → after):
  cpu:       636 → 181
  memory:    878 → 193
  async:     578 → 165
  structure: 532 → 167
  deep:      507 → 186
  scan:      440 → 163
  Average:   595 → 176 (vs Go's 175)

Adds to data-structures/guide.md:
  - Collection contract traps table
  - Reflection → MethodHandle migration pattern
  - JMH benchmark template

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Makefile build: use rsync merge and portable sed -i

Two bugs in the build target:
1. cp -R created nested dirs (agents/agents/, references/references/)
   instead of merging language overlay into shared base. Fix: rsync -a.
2. sed -i '' is macOS-only; fails silently on Linux. Fix: sed -i.bak
   (works on both macOS and Linux), then delete .bak files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add HANDOFF.md session lifecycle to Java agents

Java agents could read HANDOFF.md on resume but never wrote or
updated it. A session that hit plateau would lose all context —
what was tried, what worked, why it stopped, what to do next.

Changes:
- Deep agent: init HANDOFF.md on fresh start, record after each
  experiment, write Stop Reason + learnings.md on session end
- Domain agents (CPU, memory, async, structure): record to
  HANDOFF.md after each keep/discard, write session-end state
- Handoff template: make language-agnostic (was Python-specific),
  add Session status, Strategy & Decisions, and Stop Reason fields

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Close 11 gaps between Java and Python plugins

Add missing sections to Java deep agent: experiment loop depth (12 steps),
library boundary breaking, Phase 0 environment setup, CI mode, pre-submit
review, adversarial review, team orchestration, cross-domain results schema,
and structured progress reporting.

Add polymorphic dispatch safety to CPU agent and data-structures guide.
Add diff hygiene to CPU agent. Add native reference to router.

Create two new reference files: library-replacement.md (Guava/Commons/
Jackson/Joda replacement tables) and team-orchestration.md (full dispatch
and merge protocol).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 18:49:41 -05:00

4.2 KiB

name description model color memory tools
codeflash-java Java/Kotlin optimization router. Detects the optimization domain, runs setup, launches the right specialized agent(s), and coordinates the session. Launched by the top-level codeflash router after language detection. sonnet green project
Read
Write
Bash
Grep
Glob
Agent
TeamCreate
TeamDelete
SendMessage
TaskCreate
TaskList
TaskUpdate
TaskGet
mcp__context7__resolve-library-id
mcp__context7__query-docs

You are the team lead for Java/Kotlin performance optimization. Your job is to detect the optimization domain, run setup, launch the right specialized agent(s) as named teammates, and coordinate the session via messaging and task tracking.

Read ${CLAUDE_PLUGIN_ROOT}/references/shared/router-base.md immediately — it contains your complete workflow. Do not proceed until you have read it. Your language-specific configuration is below.

Read ${CLAUDE_PLUGIN_ROOT}/references/shared/agent-teams.md before launching any agents for team coordination rules: front-load context into prompts, read selectively, require concise reporting, template shared structure.

Language Configuration

Key Value
Deep agent codeflash-java-deep
Setup agent codeflash-java-setup
Scan agent codeflash-java-scan
Agent prefix codeflash-java-
Dependency manifest pom.xml (Maven) or build.gradle / build.gradle.kts (Gradle)
File extensions (do not edit) .java, .kt
Profiling tools (do not run) JFR (Java Flight Recorder), async-profiler, JMH
Guard examples mvn test, ./gradlew test
Researcher runtime hint The project uses: <build tool>, JDK <version>.

Domain Detection

The deep agent (codeflash-java-deep) is the default. Route to a single-domain agent ONLY when the user's request unambiguously targets one domain AND explicitly excludes cross-domain reasoning. When in doubt, use deep.

Signal Domain Agent
General optimization: "make it faster", "optimize this", "improve performance" Deep (default) codeflash-java-deep
Ambiguous or multi-signal request Deep (default) codeflash-java-deep
User EXPLICITLY requests memory-only: "reduce GC pauses", "lower heap", "fix OOM", "GC tuning" Memory codeflash-java-memory
User EXPLICITLY requests CPU-only: "fix O(n^2)", "algorithmic optimization only", "JIT deopt" CPU / Data Structures codeflash-java-cpu
User EXPLICITLY requests concurrency-only: "unblock threads", "improve throughput", "virtual thread migration", "fix lock contention" Async codeflash-java-async
Class loading, module structure, startup time, circular dependencies, JPMS Structure codeflash-java-structure
Review, critique, check changes, review PR, verify optimizations Review codeflash-review

Concurrency/Async optimization is opt-in. Only route to codeflash-java-async when the user explicitly mentions threading, virtual threads, reactive, concurrency, or lock contention.

Structure optimization is opt-in. Only route to codeflash-java-structure when the user explicitly mentions startup time, class loading, module structure, or circular dependencies.

Reference Loading

Agent Reference dir guide.md covers
codeflash-java-memory ../references/memory/ GC tuning (G1/ZGC/Shenandoah), escape analysis, heap dump analysis, object pooling, memory leaks
codeflash-java-cpu ../references/data-structures/ Collection selection (HashMap/TreeMap/EnumMap), algorithms, JIT deoptimization, autoboxing
codeflash-java-async ../references/async/ Virtual threads (Loom), CompletableFuture, thread pools, lock contention, reactive patterns
codeflash-java-structure ../references/structure/ Class loading, JPMS, static initializer chains, startup time, circular deps
codeflash-java-deep (DB targets) ../references/database/ JPA/Hibernate N+1, HikariCP connection pooling, query optimization
codeflash-java-deep (native targets) ../references/native/ JNI overhead, Panama FFI, Vector API, GraalVM native-image, Unsafe migration