refactor
Refactor existing code to improve quality, readability, architecture, consistency, simplicity, and idiomatic style — without changing observable behavior. Use this skill whenever the user says "refactor", "clean up this code", "this is messy", "too complex", "hard to read", "too much duplication", "improve code quality", or shares code with obvious structural problems. Also trigger proactively when you notice significant code smells while working on another task. Default mode is execution (make the changes); switch to plan-only if the user explicitly asks for a refactoring plan without executing changes.
- License 许可
- GPL-3.0
- 所属仓库
- Artawower/kaizen
- 最近更新
- 2026-11-10
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- refactor
- description
- Refactor existing code to improve quality, readability, architecture, consistency, simplicity, and idiomatic style — without changing observable behavior. Use this skill whenever the user says "refactor", "clean up this code", "this is messy", "too complex", "hard to read", "too much duplication", "improve code quality", or shares code with obvious structural problems. Also trigger proactively when you notice significant code smells while working on another task. Default mode is execution (make the changes); switch to plan-only if the user explicitly asks for a refactoring plan without executing changes.
02 资源文件 1
- 参考文档references/refactor-policy.md3.7 KB
03 SKILL.md 正文
Refactor
Improve existing code without changing its observable behavior.
Before starting, load the canonical policy:
references/refactor-policy.md
It contains the quality priorities, code smells catalog, techniques table, and hard rules. Treat it as the source of truth.
Scope
Unless the user specifies otherwise:
- Work on the file or code the user explicitly points to.
- If a symbol (function, class, module) is named — scope to that symbol and its direct dependencies.
- Do not expand scope to the whole codebase without explicit instruction.
Pre-condition: tests
Refactoring without tests is dangerous. Before touching any code:
- Check if tests exist for the code to be refactored.
- If tests exist — run them.
- Green → this is your baseline, proceed.
- Red → stop. Tell the user: tests are already failing before any changes. Ask whether to fix them first or proceed knowing the baseline is broken.
- If no tests exist — ask the user:
"There are no tests covering this code. Should I write characterization tests first (recommended), or proceed without them?"
- If characterization tests: write them, confirm green, then proceed.
- If user declines: proceed but note the risk explicitly.
Workflow
Default: execute
- Read the code — understand what it does before changing anything.
- Satisfy the pre-condition above.
- Identify smells using the catalog in
references/refactor-policy.md— list what is wrong and why, ordered by impact. - Plan the sequence — order changes so each step is safe and independently verifiable. Low-risk techniques first.
- Execute one change at a time:
- Apply one named technique from the policy.
- Run tests. Green → continue. Red → revert, find a smaller step.
- Check diagnostics after each change.
- Verify — run the full test suite. Confirm behavior is unchanged.
- Report each change in this format:
[Technique] file:symbol — reason
Plan-only mode
Use only when the user explicitly asks for a refactoring plan without making changes (e.g. "show me what to refactor", "give me a plan").
Do not use this mode for code review — that is a separate skill.
Output:
- Smells found, with file and rough location
- Why each is a problem
- Technique to apply (from policy)
- Suggested order, low-risk first
Constraints
- Do not implement fixes for bugs found during refactoring — note them, fix separately.
- Do not review code quality in isolation — use the
code-reviewskill for that. - Respond in the user's language.
04 同仓库更多 Skills
yt-analyze
Fetch YouTrack task + comments via MCP, critically analyze relevance and requirements, produce concise summary of what to implement, and build an implementation plan mapped to codebase. Trigger - YouTrack issue ID or request to "analyze task", "plan task", "break down YT issue".
youtrack-task
Analyzes a YouTrack issue, reviews comments and attachments, and proposes or creates actionable subtasks. Use when the user gives a YouTrack issue ID and wants synthesis, decomposition, or follow-up tasks.
youtrack-search
Searches YouTrack from natural language or native query syntax and returns a concise report with the most relevant issues. Use when the user wants to find issues, triage work, or translate a plain-language query into YouTrack search.
writing-for-agents
Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.
write-a-prd
Create a PRD through user interview, codebase exploration, and module design, then submit as a GitHub issue. Use when user wants to write a PRD, create a product requirements document, or plan a new feature.
vitest
Plan and write Vitest tests for changed code. Analyses git diff, checks existing tests, produces a concrete test plan using flat test structure (no describe/it blocks). Use when adding tests for new/changed code, improving Vitest coverage, or asking what to test after a change.