Token导航 LogoToken导航TokenDH.com
前端设计只读github未标认证来源可访问clear审计提醒

refactoring-specialist重构专家

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

11,040

周安装

451

GitHub Stars

47

下载量

3,536
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:refactoring-specialist(重构专家)
来源仓库:https://github.com/charon-fan/agent-playbook
仓库路径:skills/refactoring-specialist
安装命令:
npx skills add https://github.com/charon-fan/agent-playbook --skill refactoring-specialist
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/charon-fan/agent-playbook --skill refactoring-specialist

简介

refactoring-specialist 专注于代码重构指导,确保结构清晰、可读性强且行为不变的前提下提升可维护性。

  • 适用于 React、Vue、Next.js 等前端框架下的组件优化、样式整理和性能瓶颈排查。
  • 采用小步提交、保留行为一致性和充分测试覆盖的原则,逐步消除技术债务。
  • 涉及页面改动时需配合本地预览与构建检查,防止孤立片段影响整体布局与交互体验。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Refactoring Specialist

Expert guidance on refactoring code to improve structure, readability, and maintainability while preserving functionality.

When This Skill Activates

Activates when you:

  • Ask to refactor code
  • Request cleanup or improvement
  • Mention "technical debt" or "code smell"
  • Want to improve code quality

Refactoring Principles

  1. Preserve Behavior: Refactoring must not change external behavior
  2. Small Steps: Make small, incremental changes
  3. Test Coverage: Ensure tests pass before and after
  4. Commit Often: Commit after each successful refactoring

Code Smells to Address

1. Long Method

Symptom: Function > 20-30 lines

Refactoring: Extract Method

// Before:
function processOrder(order) {
  // 50 lines of code
}

// After:
function processOrder(order) {
  validateOrder(order);
  calculateTotals(order);
  saveOrder(order);
  sendConfirmation(order);
}

2. Duplicate Code

Symptom: Similar code in multiple places

Refactoring: Extract Method / Template Method

// Before:
class UserService {
  async validateEmail(email) {
    if (!email || !email.includes('@')) return false;
    const domain = email.split('@')[1];
    return domain.length > 0;
  }
}
class AdminService {
  async validateEmail(email) {
    if (!email || !email.includes('@')) return false;
    const domain = email.split('@')[1];
    return domain.length > 0;
  }
}

// After:
class EmailValidator {
  async validate(email) {
    if (!email || !email.includes('@')) return false;
    return email.split('@')[1].length > 0;
  }
}

3. Large Class

Symptom: Class doing too many things

Refactoring: Extract Class

// Before:
class User {
  // Authentication
  // Profile management
  // Notifications
  // Reporting
}

// After:
class User { /* Core user data */ }
class UserAuth { /* Authentication */ }
class UserProfile { /* Profile management */ }
class UserNotifier { /* Notifications */ }

4. Long Parameter List

Symptom: Function with 4+ parameters

Refactoring: Introduce Parameter Object

// Before:
function createUser(name, email, age, address, phone, role) { ... }

// After:
function createUser(user: UserData) { ... }

interface UserData {
  name: string;
  email: string;
  age: number;
  address: string;
  phone: string;
  role: string;
}

5. Feature Envy

Symptom: Method uses more data from other classes

Refactoring: Move Method

// Before:
class Report {
  formatSummary(formatter) {
    const options = formatter.getFormattingOptions();
    // ...
  }
}

// After:
class Formatter {
  formatReport(report) {
    const discount = this.discountLevel;
    // ...
  }
}

6. Data Clumps

Symptom: Same data appearing together

Refactoring: Extract Value Object

// Before:
function drawShape(x, y, width, height) { ... }
function moveShape(x, y, width, height, dx, dy) { ... }

// After:
class Rectangle {
  constructor(x, y, width, height) { ... }
}
function drawShape(rect: Rectangle) { ... }

7. Primitive Obsession

Symptom: Using primitives instead of small objects

Refactoring: Replace Primitive with Object

// Before:
function createUser(name, email, phone) { ... }

// After:
class Email {
  constructor(value) {
    if (!this.isValid(value)) throw new Error('Invalid email');
    this.value = value;
  }
  // ...
}

8. Switch Statements

Symptom: Large switch on type

Refactoring: Replace Conditional with Polymorphism

// Before:
function calculatePay(employee) {
  switch (employee.type) {
    case 'engineer': return employee.salary * 1.2;
    case 'manager': return employee.salary * 1.5;
    case 'sales': return employee.salary * 1.1;
  }
}

// After:
interface Employee {
  calculatePay(): number;
}
class Engineer implements Employee {
  calculatePay() { return this.salary * 1.2; }
}

9. Temporary Field

Symptom: Variables only used in certain scenarios

Refactoring: Extract Class

// Before:
class User {
  calculateRefund() {
    this.tempRefundAmount = 0;
    // complex calculation
    return this.tempRefundAmount;
  }
}

// After:
class RefundCalculator {
  calculate(user) {
    // ...
  }
}

10. Comments

Symptom: Code needs extensive comments

Refactoring: Extract Method with clear name

// Before:
// Calculate the total price including discounts
// and tax based on user location
function calc(u, i) {
  let t = 0;
  // discount logic
  if (u.vip) t *= 0.9;
  // tax logic
  if (u.state === 'CA') t *= 1.08;
  return t;
}

// After:
function calculateTotalPrice(user: User, items: Item[]): number {
  let total = items.sum(i => i.price);
  if (user.isVIP) {
    total = applyVIPDiscount(total);
  }
  return applyTax(total, user.state);
}

Refactoring Steps

  1. Identify the smell - What makes this code hard to work with?
  2. Determine the refactoring - Which technique applies?
  3. Ensure tests pass - Green before starting
  4. Apply the refactoring - Make the change
  5. Run tests - Verify behavior unchanged
  6. Commit - Small, atomic commits

Safe Refactoring Practices

  • Use your IDE's refactoring tools (Rename, Extract, Move)
  • Run tests frequently (after each change)
  • Keep commits small and focused
  • Write a descriptive commit message
  • Consider code reviews for complex refactorings

Before Refactoring

  • Tests are passing
  • I understand what the code does
  • I have identified the specific code smell
  • I know which refactoring to apply
  • I have a rollback plan

After Refactoring

  • Tests still pass
  • Code is more readable
  • Code is easier to maintain
  • No new code smells introduced
  • Documentation updated if needed

References

  • references/smells.md - Complete code smell catalog
  • references/techniques.md - Refactoring techniques
  • references/checklist.md - Refactoring checklist

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

27.73%
按下载量换算981

OpenCode

22.98%
按下载量换算813

Antigravity

17.05%
按下载量换算603

Codex

11.01%
按下载量换算389

Gemini CLI

7.39%
按下载量换算261

windsurf

3.15%
按下载量换算111

安全审计

Gen Agent Trust Hub

通过

Socket

可疑

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills