agentleFS
khangledoanminhkhangledoanminh/agentskillslab/skills/refactor-engineer/SKILL.md

refactor-engineer

Skill1 starsChanged 3 months agoMITView on GitHub

Detect code smells (God class, long functions, duplication, circular dependencies, bad abstractions) with real static analysis, refactor safely with regression tests as guardrails, and verify no behavior change. Use when improving code structure, reducing technical debt, or preparing legacy code for extension.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Refactor Engineer

Refactor an toàn = phát hiện thật + regression guard + verify behavior không đổi. Không refactor vì thích — refactor vì có smell cụ thể và risk được kiểm soát.

Quy trình (6 bước)

  1. Phát hiện smells (script thật): chạy scripts/detect_smells.py <repo> — tìm God class (>500 dòng, >15 method), long function (>50 dòng, >4 nested), duplication (clone detection qua normalized hashing), circular dependency (import graph), bad abstraction (deep inheritance, shotgun surgery indicators).
  2. Chọn mục tiêu: 1 smell, ưu tiên theo: frequency × sửa dễ × impact. Không refactor toàn repo cùng lúc.
  3. Establish guardrails: chạy regression test suite hiện có (hoặc viết characterization test nếu chưa có) — green trước khi chạm code.
  4. Refactor từng bước nhỏ: mỗi bước giữ behavior, chạy regression sau mỗi bước. Commit riêng từng bước.
  5. Verify: regression suite green + diff behavior kiểm tra (output các entry point không đổi) + re-run smell detector xác nhận smell giảm.
  6. Report: bảng smell trước/sau, danh sách commits, risk còn lại.

Nguyên tắc

  • Behavior preservation là bất biến — test fail = revert.
  • Một smell một lần refactor.
  • Không đổi API public nếu không cần; nếu đổi, cập nhật callers cùng lúc + doc.
  • Refactor nhỏ > refactor lớn.

Scripts

  • scripts/detect_smells.py <repo> [--thresholds FILE] — output JSON smells với severity.
  • scripts/import_graph.py <repo> — vẽ dependency graph, phát hiện cycle.

References

  • SMELL-CATALOG.md — định nghĩa + ngưỡng từng smell
  • SAFETY-CHECKLIST.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.