Clean Code Refine
Review or refactor code using multiple aspect lenses instead of letting one
style preference dominate. Functional refactoring is one useful lens, but it
must not override behavior preservation, language idiom, small functions,
complexity reduction, cohesion, testability, or simplicity.
Mode routing
- If the user asks for a review, audit, assessment, or explicitly says
review-only, do not edit. Report prioritized findings and proposed changes.
- If the user asks to fix, refactor, clean up, or approves edits,
make one coherent behavior-preserving change at a time and verify it.
- If the request is specifically FP-oriented, use
fp-refine for that aspect but
keep this skill's veto and evidence rules in force.
Core workflow
- Read repository instructions, nearby code, tests, and dependency manifests.
- Identify the target language, framework, and available verification commands.
- Build a short aspect map using
references/aspect-rubric.md only as needed.
- Rank findings by expected maintainability gain and behavior risk.
- State the intended invariant and why the change is cleaner across aspects.
- Edit narrowly, preserving public APIs and user-visible behavior unless the
user explicitly authorizes a change.
- Run the narrowest reliable test or static check. Broaden only for changed
risk, insufficient coverage, a failure, or an existing required gate.
Aspect passes
Evaluate the code through these lenses:
- Behavior and API safety — observable behavior, persistence formats,
public APIs, compatibility, and error semantics are preserved.
- Language idiom — the solution fits the language and repository style.
- Function size and shape — long functions are split around meaningful
concepts, not arbitrary line counts.
- Cyclomatic/cognitive complexity — branching, nesting, flags, and hidden
control flow are reduced or made finite and explicit.
- Cohesion and coupling — responsibilities are located together and
unrelated policies are not mixed into one abstraction.
- Data flow and state ownership — mutation, aliasing, and temporal coupling
are visible or removed; invoke
fp-refine when declarative state/data shapes
are the right remedy.
- Error handling and observability — expected failures are explicit, while
logs, traces, and diagnostics remain useful.
- Testability — pure logic becomes easier to test and integration behavior
remains covered.
- Simplicity and deletion — prefer deleting indirection or narrowing scope
over adding a framework, DSL, or generic abstraction.
Conflict resolution
When aspect recommendations conflict, use this priority order:
- Preserve behavior, data formats, and public API contracts.
- Match the language and repository idiom.
- Reduce complexity and improve locality.
- Improve testability and observability.
- Improve dataflow, immutability, and declarative structure.
- Add abstraction only when it clearly reduces repeated same-shaped code.
FP, DSLs, patterns, and architecture vocabulary do not win by default. A smaller
idiomatic function can be cleaner than a generalized pipeline. A direct match or
switch can be cleaner than a transition table. A clear loop can be cleaner than a
chain of combinators.
Refactoring rules
- Prefer the smallest change that removes a real maintenance hazard.
- Keep functions small by extracting named concepts, not by scattering every
line into a helper.
- Reduce complexity at the source: remove flags, nested conditionals, duplicate
branches, temporal coupling, and mixed responsibilities before adding an
abstraction.
- Do not introduce new dependencies, frameworks, public APIs, persistence
changes, or behavior changes without explicit authorization.
- Stop and ask when the cleanest fix requires a product decision or incompatible
API change.
Completion evidence
Report:
- the highest-priority smell addressed;
- the invariant preserved;
- the aspect tradeoffs considered, including any FP/DSL vetoes;
- files changed;
- focused and broad verification results;
- deferred risks or follow-up recommendations.
1---2name: clean-code-refine3description: Review or refactor code across multiple clean-code dimensions: behavior preservation, language idiom, function size, complexity, cohesion, FP/dataflow opportunities, testability, and simplicity. Use for clean-code review/refactoring or when fp-refine may conflict with broader readability.4---56# Clean Code Refine78Review or refactor code using multiple aspect lenses instead of letting one9style preference dominate. Functional refactoring is one useful lens, but it10must not override behavior preservation, language idiom, small functions,11complexity reduction, cohesion, testability, or simplicity.1213## Mode routing1415- If the user asks for a **review**, **audit**, **assessment**, or explicitly says16 review-only, do not edit. Report prioritized findings and proposed changes.17- If the user asks to **fix**, **refactor**, **clean up**, or approves edits,18 make one coherent behavior-preserving change at a time and verify it.19- If the request is specifically FP-oriented, use `fp-refine` for that aspect but20 keep this skill's veto and evidence rules in force.2122## Core workflow23241. Read repository instructions, nearby code, tests, and dependency manifests.252. Identify the target language, framework, and available verification commands.263. Build a short aspect map using27 [references/aspect-rubric.md](references/aspect-rubric.md) only as needed.284. Rank findings by expected maintainability gain and behavior risk.295. State the intended invariant and why the change is cleaner across aspects.306. Edit narrowly, preserving public APIs and user-visible behavior unless the31 user explicitly authorizes a change.327. Run the narrowest reliable test or static check. Broaden only for changed33 risk, insufficient coverage, a failure, or an existing required gate.3435## Aspect passes3637Evaluate the code through these lenses:38391. **Behavior and API safety** — observable behavior, persistence formats,40 public APIs, compatibility, and error semantics are preserved.412. **Language idiom** — the solution fits the language and repository style.423. **Function size and shape** — long functions are split around meaningful43 concepts, not arbitrary line counts.444. **Cyclomatic/cognitive complexity** — branching, nesting, flags, and hidden45 control flow are reduced or made finite and explicit.465. **Cohesion and coupling** — responsibilities are located together and47 unrelated policies are not mixed into one abstraction.486. **Data flow and state ownership** — mutation, aliasing, and temporal coupling49 are visible or removed; invoke `fp-refine` when declarative state/data shapes50 are the right remedy.517. **Error handling and observability** — expected failures are explicit, while52 logs, traces, and diagnostics remain useful.538. **Testability** — pure logic becomes easier to test and integration behavior54 remains covered.559. **Simplicity and deletion** — prefer deleting indirection or narrowing scope56 over adding a framework, DSL, or generic abstraction.5758## Conflict resolution5960When aspect recommendations conflict, use this priority order:61621. Preserve behavior, data formats, and public API contracts.632. Match the language and repository idiom.643. Reduce complexity and improve locality.654. Improve testability and observability.665. Improve dataflow, immutability, and declarative structure.676. Add abstraction only when it clearly reduces repeated same-shaped code.6869FP, DSLs, patterns, and architecture vocabulary do not win by default. A smaller70idiomatic function can be cleaner than a generalized pipeline. A direct match or71switch can be cleaner than a transition table. A clear loop can be cleaner than a72chain of combinators.7374## Refactoring rules7576- Prefer the smallest change that removes a real maintenance hazard.77- Keep functions small by extracting named concepts, not by scattering every78 line into a helper.79- Reduce complexity at the source: remove flags, nested conditionals, duplicate80 branches, temporal coupling, and mixed responsibilities before adding an81 abstraction.82- Do not introduce new dependencies, frameworks, public APIs, persistence83 changes, or behavior changes without explicit authorization.84- Stop and ask when the cleanest fix requires a product decision or incompatible85 API change.8687## Completion evidence8889Report:9091- the highest-priority smell addressed;92- the invariant preserved;93- the aspect tradeoffs considered, including any FP/DSL vetoes;94- files changed;95- focused and broad verification results;96- deferred risks or follow-up recommendations.