Token导航 LogoToken导航TokenDH.com
前端设计只读github未标认证来源可访问许可证需确认审计通过

refactoringrefactoring 工具

Agent Skill

refactoring 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

245

周安装

10

GitHub Stars

公开资料未说明

下载量

78
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/benmix/skills --skill refactoring

简介

实施行为保持的小步重构,改善代码结构与可维护性。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

  • 当功能难以扩展、缺陷修复受阻或理解遗留代码时使用。
  • 每次改动应聚焦单一目标,避免大规模重写引入风险。
  • 需配合测试保障行为不变,并在本地验证后再提交变更。
  • refactoring 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Refactoring

Refactor code in small, behavior-preserving steps so the next change becomes easier, safer, and cheaper.

When To Use

  • You need to improve structure without changing externally observable behavior.
  • A feature is hard to add because the current design is awkward.
  • A bug fix is blocked by confusing, tangled, or duplicated code.
  • You need to understand legacy code before touching it.
  • You want a small, safe refactoring plan instead of a vague cleanup pass.

When Not To Use

  • You are intentionally changing product behavior.
  • The code is ugly, but you do not need to touch it.
  • A rewrite is clearly cheaper and lower risk than incremental restructuring.
  • There is no practical way to verify behavior and the risk is unacceptable.

Core Rules

  • Refactoring is structural improvement that preserves observable behavior.
  • Refactoring is not rewriting.
  • Refactoring is not feature work.
  • Wear one hat at a time: Refactor hat changes structure only. Feature hat changes behavior only.
  • If both are needed, make the design change first, then make the behavioral change.

Default Loop

  1. Clarify the real goal: feature, bug fix, or comprehension.
  2. State the smell in one sentence.
  3. State the intended improvement in one sentence.
  4. Lock down current behavior with tests or the strongest repeatable check available.
  5. Choose the smallest refactoring that makes the next change easier.
  6. Apply one micro-step.
  7. Run checks immediately.
  8. Repeat only while improvement is still clear.
  9. Stop as soon as the intended change becomes straightforward.

Preferred step order:

  1. Rename
  2. Extract
  3. Move
  4. Encapsulate or inline
  5. Simplify conditionals
  6. Remove dead code

Before implementing the real task, first make the change easy.

Common early moves:

  • rename unclear symbols
  • extract a confusing block
  • split mixed phases
  • move logic to the data it depends on
  • remove duplication first

Quick Chooser

Use this as a quick chooser, not a rigid law:

  • Mysterious Name -> Rename
  • Duplicated Code -> Extract Function, Consolidate, Move Function
  • Long Function -> Extract Function, Split Phase
  • Long Parameter List -> Introduce Parameter Object, Preserve Whole Object
  • Global Data / Mutable Data -> Encapsulate Variable, Encapsulate Record, Separate Query from Modifier
  • Divergent Change / Shotgun Surgery -> Move Function, Extract Class, Combine related behavior
  • Feature Envy -> Move Function
  • Data Clumps -> Introduce Parameter Object, Extract Class
  • Primitive Obsession -> Replace Primitive with Object
  • Repeated Switches -> Replace Conditional with Polymorphism
  • Temporary Field -> Extract Class
  • Lazy Element / Middle Man -> Inline or remove the unnecessary indirection
  • Alternative Classes With Different Interfaces -> Rename, Move, Extract Superclass

Safety Rules

  • Never let the code stay broken between steps.
  • Prefer local, reversible edits before architectural ones.
  • Prefer explicit names over clever abstraction.
  • Prefer many small commits over one large commit.
  • If tests fail, assume the last step is wrong until proven otherwise.
  • Revert aggressively instead of debugging a giant diff.
  • Keep public interfaces stable unless changing them is part of the task.
  • When an interface must change across boundaries, use compatibility shims or staged migration.
  • Do not refactor unrelated areas just because they are ugly.
  • Leave the touched area a bit healthier than you found it.

Verification Ladder

Use the strongest available verification, in this order:

  1. existing automated tests
  2. new characterization tests
  3. deterministic integration checks
  4. reproducible manual checks

Working Heuristics

  • In legacy code, improve the area you must touch instead of trying to beautify everything.
  • In low-test systems, choose especially safe transformations and verify constantly.
  • Do not mix performance tuning into routine refactoring. First improve clarity, then measure, then optimize only where evidence demands it.
  • Long-lived feature branches make refactoring harder. Integrate frequently and keep branch lifetime short.
  • Stop when the next intended change is easy and the design is no longer clearly improving.

Definition Of Done

A refactoring task is done only when:

  • observable behavior is preserved
  • tests or equivalent checks pass
  • the target area is easier to understand
  • the next intended change is easier than before
  • no unnecessary abstraction was introduced

Reference Strategy

Stay in this file by default. Read references only when the default loop is not enough:

  • references/01-core-principles.md Use when you need the core definition, the "two hats" model, or the decision standard for good design.
  • references/02-workflow-and-tactics.md Use when you need the execution loop, preferred step order, verification ladder, or common refactoring tactics.
  • references/03-bad-smells-map.md Use when you can tell the code is bad but need help naming the smell and choosing the first move.
  • references/04-refactoring-priority.md Use when you want to prioritize which refactorings to learn or reach for first.
  • references/05-fowler-statement-example.md Use when you want a concrete Fowler-style example of the rhythm in practice.
  • references/06-team-process-and-tradeoffs.md Use when the refactor is long-running, low-test, performance-sensitive, cross-boundary, or collaboration-heavy.

Response Style

When using this skill, report progress as:

  1. smell observed
  2. chosen micro-refactoring
  3. verification performed
  4. resulting improvement

Default Output Contract

When asked to refactor, produce:

  • a short diagnosis of the smell
  • the minimal refactoring plan
  • the ordered micro-steps
  • the verification method
  • the final code change

One-Line Principle

For each desired change, first make the change easy, then make the easy change.

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

35.25%
按下载量换算27

Claude

30.24%
按下载量换算24

Cursor

17.61%
按下载量换算14

Gemini CLI

9.06%
按下载量换算7

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills