Refactoring
Use this skill for refactors across languages, especially code with structural duplication, unstable abstractions, or unfinished migrations.
When refactoring code:
- First identify the structural smells that matter: duplicated contracts, pass-through layers, mirror mappers, split async paths, half-migrations.
- Choose the smallest end-state that removes those smells without changing the required behavior.
- Collapse pass-through layers, duplicated contracts, mirror mappers, one-use factories, and generic dispatchers called from only a couple of concrete sites.
- For split async paths (parallel success/error/loading branches, duplicated await chains, or the same request issued from multiple owners), consolidate into one flow that returns a single result type.
- Prefer one coherent owner per behavior and one canonical data shape per concept. One owner means one module per concept; when the public name differs from the internal name, do the alias re-export from the package entry, not from a dedicated facade file.
- Export only what the public API requires. If a function becomes internal-only after consolidation, drop its export.
- Delete dead abstractions before adding helpers.
- Finish the migration in one pass. Do not keep legacy and replacement structures alive together.
- Before stopping, run the native compile, test, or lint command that already exists in the repo and fix failures you introduced.
Rule priority
When rules compete, apply in this order:
- Preserve the public API surface the repo actually exercises.
- Keep the native compile, test, or lint command green.
- Remove the structural smell.
- Reduce file count or line count.
Example: consolidating two mirror mappers into one canonical type is correct at step 3, but if it breaks a publicly imported name, step 1 wins — keep an alias re-export from the package entry until callers migrate.
Language Profiles
- For TypeScript or JavaScript module, type, and async pitfalls, read typescript-javascript.md.
- For Dart or Flutter type, widget, state, and async pitfalls, read dart-flutter.md.
- For Elixir, Phoenix, or LiveView boundary ownership and generated middle-layer cleanup, read elixir-phoenix.md.
- For other languages, keep the generic core above and follow the repository's native ownership boundaries, type system, and verification commands.
Notes
- Prefer the minimum concept set, not the minimum file count.
- Preserve externally required behavior while simplifying internals.
- A passed smoke test does not excuse a broken compile.
- If you finish with no substantive diff, the task is not complete.
Read failure-patterns.md when a first refactor attempt regresses or stalls.
Read playbook.md when you want the edit sequence for each smell family.
Not this skill
This skill does not:
- Change externally observable behavior (that is behavior-change work, not refactoring).
- Redesign the public API surface (API change, separate task).
- Add tests where none existed (test authoring, separate task).
- Apply cosmetic renames without dedup (if there is no structural smell, do not touch names).
- Review code for bugs, security, or performance (use
critical-code-review instead).
1---2name: refactoring3description: 言語横断で過剰抽象化や AI 生成コードの構造重複を安全にリファクタリングする。duplicated contract、pass-through layer、mirror mapper、split async path、half-migration を見つけ、最小の一貫した end-state に収束させる。TS/JS、Dart/Flutter、Elixir/Phoenix は専用 profile あり。「リファクタリングして」「AI生成コードを整理して」「重複型を統合して」「wrapperを潰して」で使用。4---56# Refactoring78Use this skill for refactors across languages, especially code with structural duplication, unstable abstractions, or unfinished migrations.910When refactoring code:11- First identify the structural smells that matter: duplicated contracts, pass-through layers, mirror mappers, split async paths, half-migrations.12- Choose the smallest end-state that removes those smells without changing the required behavior.13- Collapse pass-through layers, duplicated contracts, mirror mappers, one-use factories, and generic dispatchers called from only a couple of concrete sites.14- For split async paths (parallel success/error/loading branches, duplicated await chains, or the same request issued from multiple owners), consolidate into one flow that returns a single result type.15- Prefer one coherent owner per behavior and one canonical data shape per concept. One owner means one module per concept; when the public name differs from the internal name, do the alias re-export from the package entry, not from a dedicated facade file.16- Export only what the public API requires. If a function becomes internal-only after consolidation, drop its export.17- Delete dead abstractions before adding helpers.18- Finish the migration in one pass. Do not keep legacy and replacement structures alive together.19- Before stopping, run the native compile, test, or lint command that already exists in the repo and fix failures you introduced.2021## Rule priority2223When rules compete, apply in this order:24251. Preserve the public API surface the repo actually exercises.262. Keep the native compile, test, or lint command green.273. Remove the structural smell.284. Reduce file count or line count.2930Example: consolidating two mirror mappers into one canonical type is correct at step 3, but if it breaks a publicly imported name, step 1 wins — keep an alias re-export from the package entry until callers migrate.3132## Language Profiles3334- For TypeScript or JavaScript module, type, and async pitfalls, read [typescript-javascript.md](references/typescript-javascript.md).35- For Dart or Flutter type, widget, state, and async pitfalls, read [dart-flutter.md](references/dart-flutter.md).36- For Elixir, Phoenix, or LiveView boundary ownership and generated middle-layer cleanup, read [elixir-phoenix.md](references/elixir-phoenix.md).37- For other languages, keep the generic core above and follow the repository's native ownership boundaries, type system, and verification commands.3839## Notes4041- Prefer the minimum concept set, not the minimum file count.42- Preserve externally required behavior while simplifying internals.43- A passed smoke test does not excuse a broken compile.44- If you finish with no substantive diff, the task is not complete.4546Read [failure-patterns.md](references/failure-patterns.md) when a first refactor attempt regresses or stalls.47Read [playbook.md](references/playbook.md) when you want the edit sequence for each smell family.4849## Not this skill5051This skill does not:5253- Change externally observable behavior (that is behavior-change work, not refactoring).54- Redesign the public API surface (API change, separate task).55- Add tests where none existed (test authoring, separate task).56- Apply cosmetic renames without dedup (if there is no structural smell, do not touch names).57- Review code for bugs, security, or performance (use `critical-code-review` instead).