Refactor Engine
Improves existing codebases by restructuring for clarity, performance, and maintainability without changing external behavior
- License 许可
- MIT
- 最近更新
- 2026-06-22
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- Refactor Engine
- tags
- [ "refactoring", "cleanup", "optimization" ]
- author
- ForgeWeave Core
- version
- 1.0.0
- skill_id
- refactor-engine
- description
- Improves existing codebases by restructuring for clarity, performance, and maintainability without changing external behavior
- tui_compatibility
- [ "opencode", "claude", "gemini", "qwen" ]
02 资源文件 2
- 参考文档references/refactoring-patterns.md1.1 KB
- 脚本scripts/extract_function.py1.6 KB
03 SKILL.md 正文
Refactor Engine
Purpose
Restructure existing code to improve readability, performance, and maintainability while preserving exact external behavior. Every refactor is verified by ensuring existing tests continue to pass and no observable behavior changes.
When to Use
- Code has duplicated logic that should be extracted
- A function or module is too long or does too many things
- Naming is unclear or inconsistent with project conventions
- Performance can be improved by algorithmic changes
- Dead code, commented-out code, or unused imports need removal
When Not to Use
- The code has a bug — use
debuggerfirst - New features need to be added — use
code-builder - The code works fine and doesn't need changes
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
target |
string | Yes | File, module, or code area to refactor |
goal |
enum | Yes | clarity, performance, maintainability, or all |
constraints |
string | No | What must NOT change (public API, performance bounds) |
Expected Outputs
| Output | Description |
|---|---|
| Refactored code | Restructured code preserving external behavior |
| Diff summary | What changed and why |
| Verification | Test results confirming no behavior change |
Exact Workflow Steps
- Read and understand the target code fully
- Run existing tests to establish baseline
- Identify refactoring opportunities (duplication, complexity, naming)
- Apply one refactoring at a time (small, atomic changes)
- Run tests after each change to confirm no regression
- Repeat until all planned refactorings are applied
Required Checks
- [ ] All existing tests pass before and after
- [ ] No public API changed unless explicitly requested
- [ ] Each change is atomic (one concern per change)
- [ ] No dead code or debug artifacts left behind
Failure Modes
| Failure Condition | Response |
|---|---|
| Test fails after refactor | Revert last change and re-approach differently |
| Refactor touches too many files | Break into smaller, focused refactors |
| Goal is unclear | Ask for specific examples of what to improve |
References
| Reference | Path |
|---|---|
| Test Generator skill | ../test-generator/SKILL.md |
| Code Builder skill | ../code-builder/SKILL.md |
04 同仓库更多 Skills
Workflow Orchestrator
Coordinates multi-skill execution pipelines (e.g., research → plan → build → test)
Web Research
Browser-driven or scraping-based skill for real-time internet extraction using Playwright and HTTP-based fetching
Validation Engine
Checks outputs from other skills for consistency, correctness, and adherence to AGENTS.md rules
Tool Selector
Determines which tools, APIs, MCP actions, or system capabilities are required for a given task
Test Generator
Creates test plans and test cases (unit, integration, edge cases) based on existing or planned code
Skill Generator
Meta-skill that creates new SKILL.md files from research outputs and patterns discovered in execution