API安装
- 作者仓库星标 0
- 作者更新于 实时读取
- 作者仓库 skills-registry
- 领域
- AI 智能
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- Token 消耗评级
- 中等消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 底层运行要求
- Python
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 网络行为
- 仅限本地
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: refactor
description: | Use when this capability is needed. A comprehensive, technique-by-technique catalog of refacto…
category: AI 智能
runtime: Python
---
# refactor 输出预览
## PART A: 任务判断
- 适用问题:提示词、Agent 工作流、模型评估或自动化推理。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Step 0: Detect Language / Language Support Matrix / Core Philosophy”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于提示词、Agent 工作流、模型评估或自动化推理,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Step 0: Detect Language / Language Support Matrix / Core Philosophy”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、主要在本地完成、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文没有稳定的斜杠命令要求。安装验证后通常全局生效,直接在对话里点名这个 Skill 并描述任务即可。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令。
先用一个小任务确认它会围绕“Step 0: Detect Language / Language Support Matrix / Core Philosophy”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: refactor
description: | Use when this capability is needed. A comprehensive, technique-by-technique catalog of refacto…
category: AI 智能
source: tomevault-io/skills-registry
---
# refactor
## 什么时候使用
- 把「重构」相关任务沉淀成 Agent 可调用的技能 适合处理AI Agent、提示词、模型评估与自动化推理,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步骤…
- 面向提示词、Agent 工作流、模型评估或自动化推理,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Step 0: Detect Language / Language Support Matrix / Core Philosophy」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "refactor" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Step 0: Detect Language / Language Support Matrix / Core Philosophy
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Python | 读取文件、写入/修改文件、执行终端命令 | 主要在本地完成
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} Refactoring Catalog (Multi-Language)
A comprehensive, technique-by-technique catalog of refactoring best practices for any language, sourced from Martin Fowler's Refactoring: Improving the Design of Existing Code (2nd Edition) and Alexander Shvets' Refactoring in Java (Refactoring Guru). Adapted for Python, TypeScript, Go, and Rust with idiomatic examples.
Step 0: Detect Language
Before applying any technique, detect the project's stack:
| Project File | Language | Idiom Style |
|---|---|---|
pom.xml / build.gradle |
Java | OOP, Stream API |
pyproject.toml / requirements.txt / setup.py |
Python | Duck typing, comprehensions |
package.json + tsconfig.json |
TypeScript | Functional-OOP hybrid |
package.json (no tsconfig) |
JavaScript | Prototype-based, functional |
*.csproj |
C# | OOP, LINQ |
go.mod |
Go | Composition, implicit interfaces |
build.gradle.kts |
Kotlin | OOP + functional |
Gemfile |
Ruby | Duck typing, open classes |
composer.json |
PHP | OOP |
Cargo.toml |
Rust | Ownership, traits, no inheritance |
Package.swift |
Swift | Protocol-oriented |
If the language is Java, apply techniques with Java OOP, Stream API where appropriate, and the project's detected Java version constraints.
Language Support Matrix
| Concept | Python | TypeScript | Go | Rust |
|---|---|---|---|---|
| Class / struct | class |
class |
struct + methods |
struct + impl |
| Inheritance | class Child(Parent) |
extends |
Embedding (no inheritance) | Traits (no inheritance) |
| Interface / contract | Protocol / ABC |
interface |
interface (implicit) |
trait |
| Encapsulation | _private convention |
private keyword |
Unexported (lowercase) | Private by default, pub |
| Polymorphism | Duck typing + ABC | Interfaces + classes | Implicit interfaces | Trait objects + generics |
| Generics | typing.Generic[T] |
<T> |
[T any] |
<T: Trait> |
| Error handling | Exceptions | Exceptions | Error values (error) |
Result<T, E> |
| Null safety | None / Optional[T] |
null / undefined / ? |
nil (zero values) |
Option<T> |
| Collections pipeline | Comprehensions / generators | Array methods (.map, .filter) |
for range (no pipeline) |
Iterator chain (.filter().map()) |
| Pattern matching | match (3.10+) |
switch (no pattern matching) |
switch (no pattern matching) |
match (exhaustive) |
| Factory pattern | @classmethod / module function |
Static method / function | NewXxx() function |
Type::new() associated fn |
| Builder pattern | __init__ + kwargs / dataclass |
Fluent builder class | Functional options | Builder with consuming self |
For detailed concept-to-language mappings, see references/language-idioms.md.
Core Philosophy
Refactoring is the process of changing the internal structure of code without altering its observable behavior. It is a disciplined technique, not a random cleanup. The golden rule is: Cover → Modify → Refactor (always have tests before you start).
How to Use This Skill
- Detect the language (Step 0 above)
- Diagnose first: Identify the code smell (see
techniques/00-code-smells-diagnostic.md) - Check applicability: See
references/language-applicability.mdfor technique availability per language - Select technique: Each smell maps to one or more refactoring techniques
- Read the technique file: Each technique has multi-language examples (Python, TypeScript, Go, Rust)
- For Java: Use Java OOP/Stream idioms and honor Java 8 versus Java 11+ API availability
- For language idiom mapping: See
references/language-idioms.md - Apply incrementally: Small steps, test after each change, commit frequently
Technique Categories
The techniques are organized in 7 groups. Each technique has its own file in the techniques/ directory.
Group 1: Composing Methods (techniques/01-XX)
Techniques for building clean, well-structured methods. The foundation of all refactoring.
01-extract-method.md— Extract a code fragment into a named function02-inline-method.md— Replace a function call with the function body03-extract-variable.md— Give a name to a complex expression04-inline-variable.md— Remove a variable that adds no clarity05-replace-temp-with-query.md— Replace temp variables with function calls06-replace-method-with-method-object.md— Turn a complex function into its own class/struct07-substitute-algorithm.md— Replace an algorithm with a clearer version
Group 2: Moving Features (techniques/02-XX)
Techniques for placing code where it truly belongs.
08-move-method.md— Move a function to where it has more cohesion09-move-field.md— Move a field to the type that uses it most10-extract-class.md— Split a type with multiple responsibilities11-inline-class.md— Merge a type that does too little12-hide-delegate.md— Encapsulate chain navigation behind a simpler interface13-remove-middle-man.md— Remove unnecessary delegation14-move-statements.md— Move statements into/out of functions, slide statements15-split-loop.md— Separate a loop that does multiple things16-replace-loop-with-pipeline.md— Use declarative pipelines instead of imperative loops17-remove-dead-code.md— Delete unused code
Group 3: Organizing Data (techniques/03-XX)
Techniques for enriching data with behavior and protecting internal state.
18-encapsulate-variable.md— Wrap data access with getters/functions19-encapsulate-record.md— Convert data structures into objects/structs20-encapsulate-collection.md— Protect collections from external mutation21-replace-primitive-with-object.md— Create domain types instead of using raw primitives22-split-variable.md— Give each purpose its own variable23-rename-field.md— Improve field names for clarity24-replace-derived-variable-with-query.md— Calculate values on demand25-change-reference-to-value.md— Make objects immutable (Value Objects)26-change-value-to-reference.md— Share a single instance across consumers27-replace-type-code-with-subclasses.md— Convert type codes to polymorphic hierarchy
Group 4: Simplifying Conditionals (techniques/04-XX)
Techniques for taming conditional complexity.
28-decompose-conditional.md— Name condition and branches29-consolidate-conditional.md— Merge related conditions30-replace-nested-conditional-with-guard-clauses.md— Early returns for special cases31-replace-conditional-with-polymorphism.md— Use polymorphism instead of switch/if-type32-introduce-special-case.md— Null Object pattern for default behavior33-introduce-assertion.md— Document invariants with executable assertions34-replace-control-flag.md— Replace boolean flags with break/return
Group 5: Simplifying Method Calls / API Design (techniques/05-XX)
Techniques for building self-documenting interfaces.
35-change-function-declaration.md— Rename functions and change parameters36-introduce-parameter-object.md— Group related parameters into an object37-parameterize-function.md— Unify similar functions with a parameter38-remove-flag-argument.md— Replace boolean params with named functions39-preserve-whole-object.md— Pass the object instead of extracted values40-replace-parameter-with-query.md— Let the function calculate what it needs41-replace-query-with-parameter.md— Pass value as param for purity/testability42-remove-setting-method.md— Make properties read-only43-replace-constructor-with-factory.md— Use factory functions for flexible creation44-replace-function-with-command.md— Encapsulate function as object45-separate-query-from-modifier.md— CQS: separate reads from writes
Group 6: Dealing with Generalization (techniques/06-XX)
Techniques for refactoring type hierarchies and shared behavior.
46-pull-up-method.md— Move duplicated functions to shared parent/trait/interface47-push-down-method.md— Move specialized functions to specific types48-pull-up-constructor-body.md— Unify constructor/initialization logic49-extract-superclass.md— Create common parent for shared behavior50-extract-interface.md— Define a contract without implementation51-collapse-hierarchy.md— Merge unnecessary hierarchy levels52-form-template-method.md— Template Method pattern53-replace-subclass-with-delegate.md— Composition over inheritance54-replace-superclass-with-delegate.md— Replace extends with has-a55-replace-inheritance-with-delegation.md— General inheritance to delegation
Group 7: Additional Techniques (techniques/07-XX)
Cross-cutting techniques from both sources.
56-combine-functions-into-class.md— Group functions that share data57-combine-functions-into-transform.md— Enrich read-only data58-split-phase.md— Separate code into processing phases59-introduce-foreign-method.md— Extend third-party types you can't modify60-introduce-local-extension.md— Wrapper or subclass for library extension61-replace-error-code-with-exception.md— Modernize error handling62-replace-exception-with-test.md— Don't use exceptions for control flow
Diagnostic Guide
Start with techniques/00-code-smells-diagnostic.md to identify which techniques apply to your code. The diagnostic maps 24 code smells to their recommended refactoring techniques.
Applying the Skill
When given code to refactor:
- Detect the language (Step 0)
- Read
techniques/00-code-smells-diagnostic.mdto identify the smells present - For each identified smell, read the corresponding technique file(s)
- Check
references/language-applicability.md— if the technique doesn't apply to the target language, the table shows the alternative - Apply techniques in small steps, always testing between changes
- Provide idiomatic examples for the detected language
- Explain WHY each refactoring improves the code, not just HOW to do it
- For language-specific idiom translations, consult
references/language-idioms.md
Key Principles
These principles underpin every technique in the catalog:
- Names matter more than length — a well-named 1-line function is better than an inline expression
- Small steps — extract small fragments, test, commit. Never batch multiple changes
- Intention over implementation — code should communicate WHAT, not HOW
- Data and logic that change together should live together — cohesion is king
- Prefer composition over inheritance — delegation is more flexible than extends
- Immutability is a powerful preservative — immutable data is easier to reason about
- CQS (Command-Query Separation) — a function either returns a value or modifies state, never both
Reference Files
| File | Content |
|---|---|
references/language-idioms.md |
Refactoring concept → {Python, TypeScript, Go, Rust} equivalents |
references/language-applicability.md |
62-technique × language applicability matrix with alternatives |
Source: andresnator/agents-orchestrator — distributed by TomeVault.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核