refactor
Skill này làm gì
Công cụ này giúp sắp xếp và cải thiện mã của bạn. Nó hiểu bạn muốn thay đổi gì, phân tích cách các phần mã liên kết với nhau và lên kế hoạch thay đổi an toàn để tránh lỗi.
Khi nào nên dùng
- ✓Khi bạn muốn đơn giản hóa một đoạn mã phức tạp.
- ✓Khi bạn cần tách một phần mã thành một module mới.
- ✓Khi bạn muốn hiện đại hóa hoặc tái cấu trúc một dự án cũ.
Liên kết skill
https://github.com/code-yeongyu/oh-my-openagent/blob/dev/packages/shared-skills/skills/refactor/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Tái cấu trúc hàm đăng nhập để dùng mô hình xác thực mới.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI trước hết hiểu yêu cầu của bạn và phân tích toàn bộ mã để xem các phần liên kết ra sao. Sau đó, nó lập một kế hoạch chi tiết và thay đổi từng bước, kiểm tra để đảm bảo mọi thứ vẫn hoạt động.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
export const REFACTOR_TEMPLATE = `# Intelligent Refactor Command
Usage
``` /refactor <refactoring-target> [--scope=<file|module|project>] [--strategy=<safe|aggressive>]
Arguments: refactoring-target: What to refactor. Can be: - File path: src/auth/handler.ts - Symbol name: "AuthService class" - Pattern: "all functions using deprecated API" - Description: "extract validation logic into separate module"
Options: --scope: Refactoring scope (default: module) - file: Single file only - module: Module/directory scope - project: Entire codebase
--strategy: Risk tolerance (default: safe) - safe: Conservative, maximum test coverage required - aggressive: Allow broader changes with adequate coverage ```
What This Command Does
Performs intelligent, deterministic refactoring with full codebase awareness. Unlike blind search-and-replace, this command:
- Understands your intent - Analyzes what you actually want to achieve
- Maps the codebase - Builds a definitive codemap before touching anything
- Assesses risk - Evaluates test coverage and determines verification strategy
- Plans meticulously - Creates a detailed plan with Plan agent
- Executes precisely - Step-by-step refactoring with LSP and AST-grep
- Verifies constantly - Runs tests after each change to ensure zero regression
PHASE 0: INTENT GATE (MANDATORY FIRST STEP)
BEFORE ANY ACTION, classify and validate the request.
Step 0.1: Parse Request Type
| Signal | Classification | Action |
|---|---|---|
| Specific file/symbol | Explicit | Proceed to codebase analysis |
| "Refactor X to Y" | Clear transformation | Proceed to codebase analysis |
| "Improve", "Clean up" | Open-ended | MUST ask: "What specific improvement?" |
| Ambiguous scope | Uncertain | MUST ask: "Which modules/files?" |
| Missing context | Incomplete | MUST ask: "What's the desired outcome?" |
Step 0.2: Validate Understanding
Before proceeding, confirm:
- Target is clearly identified
- Desired outcome is understood
- Scope is defined (file/module/project)
- Success criteria can be articulated
If ANY of above is unclear, ASK CLARIFYING QUESTION:
``` I want to make sure I understand the refactoring goal correctly.
What I understood: [interpretation] What I'm unsure about: [specific ambiguity]
Options I see:
- [Option A] - [implications]
- [Option B] - [implications]
My recommendation: [suggestion with reasoning]
Should I proceed with [recommendation], or would you prefer differently? ```
Step 0.3: Create Initial Todos
IMMEDIATELY after understanding the request, create todos:
``` TodoWrite([ {"id": "phase-1", "content": "PHASE 1: Codebase Analysis - launch parallel explore agents", "status": "pending", "priority": "high"}, {"id": "phase-2", "content": "PHASE 2: Build Codemap - map dependencies and impact zones", "status": "pending", "priority": "high"}, {"id": "phase-3", "content": "PHASE 3: Test Assessment - analyze test coverage and verification strategy", "status": "pending", "priority": "high"}, {"id": "phase-4", "content": "PHASE 4: Plan Generation - invoke Plan agent for detailed refactoring plan", "status": "pending", "priority": "high"}, {"id": "phase-5", "content": "PHASE 5: Execute Refactoring - step-by-step with continuous verification", "status": "pending", "priority": "high"}, {"id": "phase-6", "content": "PHASE 6: Final Verification - full test suite and regression check", "status": "pending", "priority": "high"} ]) ```
PHASE 1: CODEBASE ANALYSIS (PARALLEL EXPLORATION)
Mark phase-1 as in_progress.
1.1: Launch Parallel Explore Agents (BACKGROUND)
Fire ALL of these simultaneously using `call_omo_agent`:
``` // Agent 1: Find the refactoring target call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find all occurrences and definitions of [TARGET]. Report: file paths, line numbers, usage patterns." )
// Agent 2: Find related code call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find all code that imports, uses, or depends on [TARGET]. Report: dependency chains, import graphs." )
// Agent 3: Find similar patterns call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find similar code patterns to [TARGET] in the codebase.
…
Câu hỏi thường gặp
“Refactor” nghĩa là gì?
Tái cấu trúc là sắp xếp lại mã có sẵn mà không thay đổi chức năng của nó, chỉ để làm mã gọn gàng, hiệu quả hơn hoặc dễ hiểu hơn.
AI đảm bảo không làm hỏng mã bằng cách nào?
Nó phân tích độ phủ kiểm thử hiện có và chạy các bài kiểm thử sau mỗi thay đổi nhỏ để đảm bảo không có gì bị hỏng (hồi quy).
Tôi có thể yêu cầu tái cấu trúc cả một tệp hay chỉ một phần không?
Có, bạn có thể chỉ định việc tái cấu trúc nằm trong một tệp, một module (thư mục) hay toàn bộ dự án.
Chi tiết
Mô tả gốc của tác giả
Guides a refactor, cleanup, or restructure with the right decomposition. Use when the user asks to refactor, simplify, extract, or modernize code.
Độ phổ biến
- Sao GitHub
- 70k
- Vị trí xếp hạng
- #3137
- Giấy phép
- NOASSERTION
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
comment-checker
70kGiúp agent của bạn hiểu và phản hồi các nhận xét từ công cụ kiểm tra bình luận tự động. Hữu ích khi xử lý kết quả từ việc rà soát mã hoặc nội dung tự động.
lcx-contribute-bug-fix
70kGiúp agent của bạn đóng góp bản sửa lỗi cho các dự án liên quan đến LazyCodex. Agent tạo issue hoặc pull request để đảm bảo chất lượng mã.
lcx-doctor
70kCho phép agent của bạn kiểm tra tình trạng cài đặt LazyCodex và Codex CLI. Hữu ích khi hệ thống hoạt động lạ sau khi cập nhật hoặc thay đổi.
lcx-report-bug
70kGiúp agent của bạn báo lỗi chi tiết cho các dự án LazyCodex. Agent tạo issue với thông tin hữu ích để lập trình viên sửa vấn đề.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.