Token导航 LogoToken导航

Agent Skill · 研究检索

refactoring(refactoring 工具)

refactoring 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

refactoring 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证为 MIT,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 43,364。

总安装 989周安装 40GitHub Stars 47下载 310核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

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

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

命令行安装

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

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

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

refactoring 提供代码质量改进与架构优化建议,聚焦技术债务清理。适用于大型函数拆分、依赖解耦与设计模式应用指导。输出包含具体重构步骤与测试覆盖保障说明。执行前应评估对现有 CI/CD 流程的影响,确保回滚机制就绪。

适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/refactoring

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/cosmix/loom --skill refactoring;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

refactoring 怎么安装?

在终端执行 npx skills add https://github.com/cosmix/loom --skill refactoring。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

refactoring 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

refactoring 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

refactoring 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

refactoring 用的人多吗?

公开数据是累计安装 989 次,近一周安装 40 次,下载 310 次,GitHub 47 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

refactoring 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
refactoring

refactoring 工具 · 本页

98947需要联网MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Refactoring

Overview

This skill focuses on improving code quality through systematic refactoring techniques. It identifies code smells and applies proven refactoring patterns to enhance maintainability while preserving functionality.

Use this skill when the user requests:

  • Code restructuring or cleanup
  • Reducing technical debt
  • Improving code organization
  • Applying design patterns
  • Breaking up large files or functions
  • Removing duplication
  • Modernizing legacy code
  • Improving testability

Scope Selection

When to use this skill:

  • Local refactoring (single module/file)
  • Pattern application (extract method, introduce interface)
  • Test refactoring and test suite improvements
  • Data pipeline restructuring
  • Safe refactoring with test coverage

Agent selection: Use senior-software-engineer (Opus) for all refactoring work. Use software-engineer (Sonnet) ONLY for mechanical renames or boilerplate following established patterns.

Instructions

1. Identify Refactoring Opportunities

Code Smells to Search For:

  • Long methods (>50 lines) or large classes (>300 lines)
  • Duplicated code blocks
  • High cyclomatic complexity
  • Magic numbers and string literals
  • Deep nesting (>3 levels)
  • Feature envy (method using data from another class)
  • Shotgun surgery (one change requires many edits)
  • Data clumps (same group of parameters)
  • Primitive obsession (using primitives instead of objects)

Use Grep/Glob to find patterns:

# Find long functions (rough heuristic)
rg "^(\s*)(def|function|fn|func)\s+\w+" --after-context=60

# Find duplicated code
rg --multiline "pattern.*\n.*pattern"

# Find magic numbers
rg "\b\d{2,}\b" --type=py --type=js --type=rs

2. Plan the Refactoring

Before starting:

  1. Verify test coverage - Run tests to establish baseline
  2. List all changes - Document sequence of refactorings
  3. Identify dependencies - What code depends on what you're changing?
  4. Plan rollback points - Where can you safely commit?
  5. Check for impact - Grep for references to functions/classes being changed

Red flags that require escalation:

  • No test coverage exists
  • Changes affect public APIs with external consumers
  • Unclear ownership or multiple teams involved
  • Performance-critical hot paths

3. Apply Refactoring Patterns

Code Organization Patterns

Extract Method/Function:

  • Break down long functions into smaller, focused ones
  • Each function should do one thing
  • Improves readability and testability

Extract Class:

  • Split large classes with multiple responsibilities
  • Follow Single Responsibility Principle
  • Improves cohesion and reduces coupling

Move Method/Field:

  • Relocate methods to classes that use their data
  • Reduces feature envy
  • Improves encapsulation

Inline Method/Variable:

  • Remove unnecessary indirection
  • Simplify overly abstracted code
  • Use when abstraction doesn't add value

Rename:

  • Improve naming clarity
  • Use domain language
  • Make intent explicit
Structural Patterns

Replace Conditional with Polymorphism:

  • Replace type switches with subclass methods
  • Enables Open/Closed Principle
  • Improves extensibility

Introduce Parameter Object:

  • Group related parameters into objects
  • Reduces parameter lists
  • Makes data relationships explicit

Replace Magic Numbers with Constants:

  • Define named constants for literals
  • Improves readability and maintainability
  • Centralizes configuration

Decompose Conditional:

  • Extract complex conditions into named functions
  • Replace nested ifs with guard clauses
  • Improves readability
Test Refactoring Patterns

Extract Test Fixture:

  • Move common setup into fixture/factory
  • Reduces duplication in test files
  • Improves test maintainability

Introduce Test Data Builder:

  • Replace complex object construction with builders
  • Makes test intent clearer
  • Simplifies test setup

Replace Assertion Roulette:

  • Use descriptive assertion messages
  • One logical assertion per test
  • Clear failure messages

Extract Test Helper:

  • Move repeated test logic into helpers
  • Keep tests focused on behavior
  • Improves test readability
Data Pipeline Patterns

Extract Transformation:

  • Isolate data transformation logic
  • Make transformations composable
  • Improves testability

Introduce Pipeline Interface:

  • Define standard input/output contracts
  • Enable stage composition
  • Simplifies testing and debugging

Replace Inline Processing with Stages:

  • Break monolithic processing into stages
  • Each stage has single responsibility
  • Enables parallelization and monitoring

4. Safe Refactoring Workflow

For each refactoring step:

  1. Make the change - One refactoring at a time
  2. Run tests - Verify behavior preserved
  3. Commit - Create checkpoint with clear message
  4. Repeat - Move to next refactoring

If tests fail:

  • Revert immediately (git checkout)
  • Analyze failure - is it a test issue or behavior change?
  • Fix or adjust approach

Commit message format:

refactor: extract calculate_discount from process_order

Improves testability by isolating discount logic.
No behavior change.

5. Verify Changes

Verification checklist:

  • All tests pass (existing + any new tests)
  • No regressions in functionality
  • Performance hasn't degraded (for hot paths)
  • Code coverage maintained or improved
  • Linting passes
  • Build succeeds

For large refactorings:

  • Run additional smoke tests
  • Check memory usage (if applicable)
  • Review error handling preservation

Best Practices

  1. Small Steps: Make incremental changes, not big bang rewrites
  2. Test First: Ensure tests exist before refactoring - write them if missing
  3. One Thing at a Time: Focus on single refactoring per commit
  4. Preserve Behavior: External behavior must remain unchanged
  5. Keep It Working: Code should pass tests after each step
  6. Document Intent: Explain why refactoring was needed in commits
  7. Refactor Tests Too: Keep tests clean and maintainable
  8. Use Type Safety: Leverage type systems to catch errors early
  9. Measure Don't Guess: Profile before optimizing performance
  10. Know When to Stop: Don't over-engineer or add unnecessary abstraction

Common Patterns with Examples

Pattern 1: Extract Method

# Before: Long method with multiple responsibilities
def process_order(order):
    # Validate order
    if not order.items:
        raise ValueError("Empty order")
    if order.total < 0:
        raise ValueError("Invalid total")

    # Calculate discount
    discount = 0
    if order.customer.is_premium:
        discount = order.total * 0.1
    if order.total > 1000:
        discount += order.total * 0.05

    # Apply discount and save
    order.final_total = order.total - discount
    order.save()

# After: Extracted methods with single responsibility
def process_order(order):
    validate_order(order)
    discount = calculate_discount(order)
    finalize_order(order, discount)

def validate_order(order):
    if not order.items:
        raise ValueError("Empty order")
    if order.total < 0:
        raise ValueError("Invalid total")

def calculate_discount(order) -> float:
    discount = 0
    if order.customer.is_premium:
        discount = order.total * 0.1
    if order.total > 1000:
        discount += order.total * 0.05
    return discount

def finalize_order(order, discount: float):
    order.final_total = order.total - discount
    order.save()

Pattern 2: Replace Magic Numbers with Constants

// Before
if (response.status === 200) {
  setTimeout(retry, 3000);
  if (attempts > 5) {
    throw new Error("Max retries exceeded");
  }
}

// After
const HTTP_OK = 200;
const RETRY_DELAY_MS = 3000;
const MAX_RETRY_ATTEMPTS = 5;

if (response.status === HTTP_OK) {
  setTimeout(retry, RETRY_DELAY_MS);
  if (attempts > MAX_RETRY_ATTEMPTS) {
    throw new Error("Max retries exceeded");
  }
}

Pattern 3: Replace Nested Conditionals with Guard Clauses

# Before
def get_payment_amount(employee):
    if employee.is_active:
        if employee.is_full_time:
            if employee.tenure > 5:
                return employee.salary * 1.1
            else:
                return employee.salary
        else:
            return employee.hourly_rate * employee.hours
    else:
        return 0

# After
def get_payment_amount(employee):
    if not employee.is_active:
        return 0

    if not employee.is_full_time:
        return employee.hourly_rate * employee.hours

    if employee.tenure > 5:
        return employee.salary * 1.1

    return employee.salary

Pattern 4: Introduce Parameter Object

// Before
function createUser(
  firstName: string,
  lastName: string,
  email: string,
  phone: string,
  street: string,
  city: string,
  state: string,
  zip: string,
) {
  // ...
}

// After
interface UserDetails {
  name: PersonName;
  contact: ContactInfo;
  address: Address;
}

interface PersonName {
  first: string;
  last: string;
}

interface ContactInfo {
  email: string;
  phone: string;
}

interface Address {
  street: string;
  city: string;
  state: string;
  zip: string;
}

function createUser(details: UserDetails) {
  // ...
}

Pattern 5: Replace Type Code with Polymorphism

// Before
enum ShapeType { Circle, Rectangle, Triangle }

struct Shape {
    shape_type: ShapeType,
    radius: f64,
    width: f64,
    height: f64,
    base: f64,
}

impl Shape {
    fn area(&self) -> f64 {
        match self.shape_type {
            ShapeType::Circle => 3.14159 * self.radius * self.radius,
            ShapeType::Rectangle => self.width * self.height,
            ShapeType::Triangle => 0.5 * self.base * self.height,
        }
    }
}

// After
trait Shape {
    fn area(&self) -> f64;
}

struct Circle { radius: f64 }
struct Rectangle { width: f64, height: f64 }
struct Triangle { base: f64, height: f64 }

impl Shape for Circle {
    fn area(&self) -> f64 {
        3.14159 * self.radius * self.radius
    }
}

impl Shape for Rectangle {
    fn area(&self) -> f64 {
        self.width * self.height
    }
}

impl Shape for Triangle {
    fn area(&self) -> f64 {
        0.5 * self.base * self.height
    }
}

Pattern 6: Extract Data Pipeline Stage

# Before: Monolithic processing
def process_data(raw_data):
    # Validate
    if not raw_data:
        raise ValueError("Empty data")

    # Clean
    cleaned = []
    for item in raw_data:
        if item.get('status') == 'valid':
            cleaned.append(item)

    # Transform
    transformed = []
    for item in cleaned:
        transformed.append({
            'id': item['id'],
            'value': item['raw_value'] * 100,
            'timestamp': item['ts']
        })

    # Aggregate
    total = sum(item['value'] for item in transformed)
    return {'items': transformed, 'total': total}

# After: Pipeline with composable stages
def validate_input(raw_data):
    if not raw_data:
        raise ValueError("Empty data")
    return raw_data

def filter_valid(data):
    return [item for item in data if item.get('status') == 'valid']

def transform_items(data):
    return [
        {
            'id': item['id'],
            'value': item['raw_value'] * 100,
            'timestamp': item['ts']
        }
        for item in data
    ]

def aggregate_results(transformed):
    total = sum(item['value'] for item in transformed)
    return {'items': transformed, 'total': total}

def process_data(raw_data):
    return (raw_data
            |> validate_input
            |> filter_valid
            |> transform_items
            |> aggregate_results)

Pattern 7: Simplify Test with Builder

// Before
func TestUserRegistration(t *testing.T) {
    user := &User{
        FirstName: "John",
        LastName: "Doe",
        Email: "john@example.com",
        Phone: "555-0100",
        Address: Address{
            Street: "123 Main St",
            City: "Springfield",
            State: "IL",
            Zip: "62701",
        },
        Preferences: Preferences{
            NewsletterEnabled: true,
            Theme: "dark",
        },
        CreatedAt: time.Now(),
    }

    err := RegisterUser(user)
    assert.NoError(t, err)
}

// After
func TestUserRegistration(t *testing.T) {
    user := NewUserBuilder().
        WithName("John", "Doe").
        WithEmail("john@example.com").
        Build()

    err := RegisterUser(user)
    assert.NoError(t, err)
}

// Test builder focuses on what matters for each test
func TestUserWithNewsletter(t *testing.T) {
    user := NewUserBuilder().WithNewsletter(true).Build()
    // ...
}

When to Stop Refactoring

Stop if:

  • Tests start failing unexpectedly
  • Scope is expanding beyond initial plan
  • Unsure about architectural implications
  • Performance concerns arise
  • Security implications unclear

In these cases:

  • Commit current progress
  • Document remaining work
  • Use senior-software-engineer or relevant specialist to continue

平台分布

Claude Code

31.72%
按下载量换算98

OpenCode

21.48%
按下载量换算67

Antigravity

16.37%
按下载量换算51

Codex

13.29%
按下载量换算41

Gemini CLI

8.52%
按下载量换算26

Cursor

3.19%
按下载量换算10

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills