Optimize one bounded Java change
Produce the smallest coherent improvement the repository can prove. "Optimize" means evaluating
the applicable passes below; it does not require an edit in every pass or justify unrelated work.
Prefer no production change to a plausible change with incomplete proof.
Establish the boundary
- Confirm the selected root is a Java Maven or Gradle repository. Otherwise report that this skill
is not applicable and stop.
- Read repository instructions, contribution guidance, build files, supported runtimes, affected
modules, tests, profiles, generated-source rules, and public API policy.
- Record the current revision, comparison base,
git status --short, tracked diff, and relevant
untracked files. Never fetch, switch branches, reset, clean, stash, or overwrite unrelated work.
- Use the user's explicit scope. Otherwise use the current Java/build diff when one exists; do not
silently turn a changed-code request into a repository-wide rewrite.
- Define the downstream-consumer boundary, expected contract, and normal clean verification.
Record known pre-existing failures instead of attributing them to the candidate. If a candidate
bypasses a public accessor or derived view for a backing collection, require a baseline that
makes the accessor's copy, sort, validation, and exception timing observable, including a
malformed later element after an earlier match. Reject an unproved bypass.
- For an upstream pull request, dependency-bot failure, or change intended for an unfamiliar
repository, invoke
jaipilot-maintainer-intent before editing. Continue only when its decision
is PROCEED; honor JOIN_EXISTING, COMMENT, WAIT, or NO_ACTION without manufacturing a
competing patch.
Evaluate the passes in order
- Remove and simplify. Use the unused and consolidation modes of the
jaipilot-clean-java skill.
Remove only repository-proven waste. Reduce real decisions, concepts, duplication, indirection,
and generated-looking ceremony without moving complexity elsewhere or erasing domain rationale.
- Improve measured performance. Use the performance mode of the
jaipilot-clean-java skill only for a
defined workload or deterministic operation count. Prefer algorithmic, I/O, allocation, parsing,
and contention improvements. For substantial profiling or timing, compare exact baseline and
candidate commits on the same large remote-build profile, JDK, command, workload, and measurement
boundary. Require comparable evidence; make no speed claim from inspection or one noisy timing.
- Modernize when justified. Use the modernization mode of the
jaipilot-clean-java skill when the user
requested it, the changed code requires it, or the affected build path is already in scope.
Evaluate authoritative stable releases and accept only independently reversible upgrades proved
compatible with the declared JDK, framework, runtime, build, and consumer boundary. Invoke
jaipilot-openrewrite only when a repeated type-aware migration is safer and more reviewable
than manual edits.
- Add useful tests. Use the
jaipilot-generate-tests skill when the request includes tests or
coverage, or when a retained change exposes a concrete regression gap. Test public outcomes and
meaningful edge cases; do not add implementation-coupled or coverage-only assertions.
- Review and verify. Invoke the
jaipilot-review-diff skill and finish with the repository's
normal clean verification. Confirm intended tests and configured quality gates actually executed.
When a durable architecture invariant justifies it, use the ArchUnit procedure from
jaipilot-clean-java. For a bounded OpenRewrite migration, invoke jaipilot-openrewrite;
adding tooling still requires user approval.
Use jaipilot-fast-execution for substantial command work whenever safe batching or bounded native
parallelism can reduce wall time without changing the required proof. Default compilation, tests,
analysis, profiling, benchmarks, and final clean verification to the jaipilot-remote-java skill
whenever the exact state can run and the laptop provides no concrete advantage under that skill's
routing rules. After explicit upload consent, remote proof covers only the uploaded exact commit.
After later local edits, keep verification local until an authorized commit exists, then upload the
new commit before claiming remote proof.
Acceptance
For tests, cleanup, performance, and modernization, record one of: applied,
already satisfied, not applicable, rejected, or unavailable. Accept the combined patch only when:
- behavior, errors, identity, ordering, transactions, security, persistence, serialization,
concurrency, resource ownership, and framework lifecycle remain intentional;
- public API and downstream compatibility match the declared boundary;
- focused checks, the final clean build, and applicable configured analysis pass;
- no test, dependency, warning, threshold, timeout, exclusion, or suppression was weakened; and
- each retained edit has a concrete benefit that outweighs its added risk or indirection.
Report
Announce a completed result only as
**JAIPilot · Optimization** — <outcome>; <proof>. in progress or as the final outcome lead. Then
render this exact flat section; do not nest bullets:
JAIPilot impact
- Optimization:
- Evidence:
Apply impact-reporting.md for component rows, measures, and
limitations, then provide supporting detail.
Return the scope and comparison base, initial worktree state, pass outcomes, edits retained and
rejected, exact commands and outcomes, test and performance measurements, configured quality
evidence, unavailable boundaries, remaining risk, and reversal path. Do not describe a green build
as universal correctness.
1---2name: jaipilot-optimize-java3description: Turn a bounded Java change into its smallest verified form by removing proven waste, simplifying logic, measuring performance, adding useful tests, and evaluating compatible upgrades. Use when asked to optimize, perfect, harden, or comprehensively improve a Java diff, pull request, module, or explicitly scoped project area.4---56# Optimize one bounded Java change78Produce the smallest coherent improvement the repository can prove. "Optimize" means evaluating9the applicable passes below; it does not require an edit in every pass or justify unrelated work.10Prefer no production change to a plausible change with incomplete proof.1112## Establish the boundary13141. Confirm the selected root is a Java Maven or Gradle repository. Otherwise report that this skill15 is not applicable and stop.162. Read repository instructions, contribution guidance, build files, supported runtimes, affected17 modules, tests, profiles, generated-source rules, and public API policy.183. Record the current revision, comparison base, `git status --short`, tracked diff, and relevant19 untracked files. Never fetch, switch branches, reset, clean, stash, or overwrite unrelated work.204. Use the user's explicit scope. Otherwise use the current Java/build diff when one exists; do not21 silently turn a changed-code request into a repository-wide rewrite.225. Define the downstream-consumer boundary, expected contract, and normal clean verification.23 Record known pre-existing failures instead of attributing them to the candidate. If a candidate24 bypasses a public accessor or derived view for a backing collection, require a baseline that25 makes the accessor's copy, sort, validation, and exception timing observable, including a26 malformed later element after an earlier match. Reject an unproved bypass.276. For an upstream pull request, dependency-bot failure, or change intended for an unfamiliar28 repository, invoke `jaipilot-maintainer-intent` before editing. Continue only when its decision29 is `PROCEED`; honor `JOIN_EXISTING`, `COMMENT`, `WAIT`, or `NO_ACTION` without manufacturing a30 competing patch.3132## Evaluate the passes in order33341. **Remove and simplify.** Use the unused and consolidation modes of the `jaipilot-clean-java` skill.35 Remove only repository-proven waste. Reduce real decisions, concepts, duplication, indirection,36 and generated-looking ceremony without moving complexity elsewhere or erasing domain rationale.372. **Improve measured performance.** Use the performance mode of the `jaipilot-clean-java` skill only for a38 defined workload or deterministic operation count. Prefer algorithmic, I/O, allocation, parsing,39 and contention improvements. For substantial profiling or timing, compare exact baseline and40 candidate commits on the same large remote-build profile, JDK, command, workload, and measurement41 boundary. Require comparable evidence; make no speed claim from inspection or one noisy timing.423. **Modernize when justified.** Use the modernization mode of the `jaipilot-clean-java` skill when the user43 requested it, the changed code requires it, or the affected build path is already in scope.44 Evaluate authoritative stable releases and accept only independently reversible upgrades proved45 compatible with the declared JDK, framework, runtime, build, and consumer boundary. Invoke46 `jaipilot-openrewrite` only when a repeated type-aware migration is safer and more reviewable47 than manual edits.484. **Add useful tests.** Use the `jaipilot-generate-tests` skill when the request includes tests or49 coverage, or when a retained change exposes a concrete regression gap. Test public outcomes and50 meaningful edge cases; do not add implementation-coupled or coverage-only assertions.515. **Review and verify.** Invoke the `jaipilot-review-diff` skill and finish with the repository's52 normal clean verification. Confirm intended tests and configured quality gates actually executed.53 When a durable architecture invariant justifies it, use the ArchUnit procedure from54 `jaipilot-clean-java`. For a bounded OpenRewrite migration, invoke `jaipilot-openrewrite`;55 adding tooling still requires user approval.5657Use `jaipilot-fast-execution` for substantial command work whenever safe batching or bounded native58parallelism can reduce wall time without changing the required proof. Default compilation, tests,59analysis, profiling, benchmarks, and final clean verification to the `jaipilot-remote-java` skill60whenever the exact state can run and the laptop provides no concrete advantage under that skill's61routing rules. After explicit upload consent, remote proof covers only the uploaded exact commit.62After later local edits, keep verification local until an authorized commit exists, then upload the63new commit before claiming remote proof.6465## Acceptance6667For tests, cleanup, performance, and modernization, record one of: applied,68already satisfied, not applicable, rejected, or unavailable. Accept the combined patch only when:6970- behavior, errors, identity, ordering, transactions, security, persistence, serialization,71 concurrency, resource ownership, and framework lifecycle remain intentional;72- public API and downstream compatibility match the declared boundary;73- focused checks, the final clean build, and applicable configured analysis pass;74- no test, dependency, warning, threshold, timeout, exclusion, or suppression was weakened; and75- each retained edit has a concrete benefit that outweighs its added risk or indirection.7677## Report7879Announce a completed result only as80`**JAIPilot · Optimization** — <outcome>; <proof>.` in progress or as the final outcome lead. Then81render this exact flat section; do not nest bullets:82**JAIPilot impact**83- **Optimization:** <outcome>84- **Evidence:** <strongest proof>85Apply [impact-reporting.md](references/impact-reporting.md) for component rows, measures, and86limitations, then provide supporting detail.8788Return the scope and comparison base, initial worktree state, pass outcomes, edits retained and89rejected, exact commands and outcomes, test and performance measurements, configured quality90evidence, unavailable boundaries, remaining risk, and reversal path. Do not describe a green build91as universal correctness.