Token导航 LogoToken导航

Agent Skill · 研究检索

code-refactor(代码重构)

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

code-refactor 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证为 MIT,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 64,698。

总安装 294周安装 12GitHub Stars 公开资料未说明下载 95核验 2026-05-01

安装说明

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

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/baggiponte/skills --skill code-refactor

这个 Skill 是做什么的

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

用于系统性重构代码组件,包含行为分析、变更提案与测试计划三阶段。适合深入分析依赖、提出具体修改建议并制定回归测试策略。输出为结构化 markdown 文档,便于评审后实施。需指定输出目录,保留现有代码结构与测试用例。code-refactor 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/code-refactor

上手步骤

4 步
  1. 1

    确认自己的宿主工具

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

  2. 2

    拿到安装命令

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

  3. 3

    安装后重启宿主

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

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

code-refactor 怎么安装?

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

code-refactor 支持哪些 AI 工具?

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

code-refactor 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

code-refactor 是免费的吗?

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

code-refactor 用的人多吗?

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

code-refactor 安全吗?

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

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

值得选的地方

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

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

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

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要厂商级技术支持和 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调用外部服务未明确有提醒
code-refactor

代码重构 · 本页

294—接触敏感数据MIT通过

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

SKILL.md 原文

Code Refactor

Overview

This skill guides systematic refactoring of one or more codebase components through three phases:

  1. Research - Deep analysis of component behavior, usage patterns, and dependencies
  2. Proposal - Concrete change suggestions with code samples and impact analysis
  3. Test Plan - Test strategy to validate changes without regressions

Each phase produces a markdown document, creating a complete refactoring proposal that can be reviewed before implementation.

Output Structure

Ask the user for an output directory (e.g., ./docs/refactoring/ or ./proposals/).

Create a subfolder for the refactoring effort:

{output-directory}/
└── {component-name}-refactor/
    ├── 01-research.md      # Phase 1: Component Analysis
    ├── 02-proposal.md      # Phase 2: Change Proposals
    └── 03-test-plan.md     # Phase 3: Test Strategy

For multi-component refactoring, create subfolders:

{output-directory}/
└── {thread-name}-refactor/
    ├── component-a/
    │   ├── 01-research.md
    │   ├── 02-proposal.md
    │   └── 03-test-plan.md
    └── component-b/
        ├── 01-research.md
        ├── 02-proposal.md
        └── 03-test-plan.md

Phase 1: Research

Goal: Comprehensive understanding of the component before proposing changes.

For multi-component refactoring, use parallel Explore agents to research each component simultaneously, then synthesize findings.

Step 1: Component Inventory (Use /codebase-librarian)

Start with the /codebase-librarian skill to establish baseline understanding:

  • Project foundation (language, tooling)
  • Entry points relevant to the component
  • Services the component interacts with
  • Infrastructure dependencies
  • Domain model elements involved

This provides context for the deeper component analysis that follows.

Step 2: Component Deep Dive

After the inventory, analyze the specific component(s) being refactored.

Understand how it works:

  • Core responsibilities and behavior
  • Internal structure and control flow
  • State management and data transformations
  • Error handling patterns
  • Configuration and initialization

Understand instantiation and usage:

  • Where is it instantiated?
  • How many instantiation patterns exist?
  • What parameters/dependencies are injected?
  • Is it a singleton, factory-created, or ad-hoc?

Map the surroundings:

  • Dependents (what calls this component)
  • Dependencies (what this component calls)
  • Before: What happens before invocation?
  • After: What happens after invocation?

Step 3: Call Graph

Create a visual representation of the component's call relationships:

┌─────────────────────────────────────────────────────────────┐
│                        CALLERS                              │
├─────────────────────────────────────────────────────────────┤
│  OrderController.create()  ──┐                              │
│  OrderController.update()  ──┼──► PaymentService            │
│  CheckoutWorker.process()  ──┘                              │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                    PaymentService                           │
├─────────────────────────────────────────────────────────────┤
│  processPayment()                                           │
│  refundPayment()                                            │
│  validateCard()                                             │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                      DEPENDENCIES                           │
├─────────────────────────────────────────────────────────────┤
│  StripeClient          │  PaymentRepository                 │
│  FraudDetectionService │  EventEmitter                      │
└─────────────────────────────────────────────────────────────┘

Research Output Format

Write to 01-research.md:

# Research: [Component Name]

**Generated**: [Date]
**Scope**: [Component path/module]

## Executive Summary

[2-3 paragraphs covering:]
- Component's purpose and role in the system
- Key findings about current implementation
- Areas of concern or complexity discovered

## Component Analysis

### Core Behavior
[What the component does, its responsibilities]

### Internal Structure
[Classes, functions, modules that compose it]

### State & Data Flow
[How data moves through the component]

## Instantiation Patterns

| Location | Pattern | Parameters | Frequency |
|----------|---------|------------|-----------|
| `src/api/orders.ts:45` | Direct new | config, logger | 3 places |
| `src/workers/checkout.ts:12` | Factory | config | 1 place |

## Dependency Analysis

### Dependents (Who calls this)

| Caller | Method | Context |
|--------|--------|---------|
| `OrderController` | `processPayment()` | HTTP request handling |
| `CheckoutWorker` | `processPayment()` | Background job |

### Dependencies (What this calls)

| Dependency | Usage | Abstracted? |
|------------|-------|-------------|
| `StripeClient` | Payment processing | No - direct SDK |
| `PaymentRepository` | Persistence | Yes - interface |

### Execution Context

**Before invocation**: [What typically happens before this component is called]
**After invocation**: [What happens with the result]

## Call Graph

[ASCII diagram as shown above]

## Key Observations

- [Notable pattern or concern 1]
- [Notable pattern or concern 2]
- [Areas that may need attention during refactoring]

Phase 2: Proposal

Persona: Pragmatic Senior Engineer

*Mindset: Balance ideal architecture with practical constraints. Quick wins build momentum and trust. Large changes need clear justification. Every change should have a clear "why".*

Proposal Structure

Order changes from quick wins to complex restructuring:

  1. Quick Wins - Small, low-risk improvements (hours)
  2. Medium Changes - Meaningful refactoring (days)
  3. Large Restructuring - Significant architectural changes (weeks)

For Each Change

Provide:

  1. Problem Statement - What's wrong and why it matters
  2. Proposed Solution - Concrete approach
  3. Code Samples - Before and after comparisons
  4. Impact Analysis - Files affected, risks, dependencies
  5. Pros and Cons - Honest trade-off assessment

Proposal Output Format

Write to 02-proposal.md:

# Refactoring Proposal: [Component Name]

**Generated**: [Date]
**Based on**: 01-research.md

## Executive Summary

[Overview of proposed changes, expected benefits, and effort distribution]

---

## Quick Wins

### 1. [Change Title]

**Problem**
[What's wrong - reference research findings]

**Solution**
[What to do]

**Before**

// src/services/payment.ts:45-52 class PaymentService { constructor() { this.stripe = new Stripe(process.env.STRIPE_KEY); } }


**After**

// src/services/payment.ts:45-55 class PaymentService { constructor(private readonly paymentGateway: PaymentGateway) {} }

// src/ports/payment-gateway.ts (new) interface PaymentGateway { charge(amount: number, currency: string): Promise<ChargeResult>; }


**Impact**

- Files modified: `src/services/payment.ts`, `src/composition-root.ts`
- Files created: `src/ports/payment-gateway.ts`
- Risk: Low - constructor signature change requires updating instantiation sites

**Pros**

- Enables unit testing without Stripe sandbox
- Prepares for potential payment provider switch

**Cons**

- Adds indirection layer
- Requires updating 3 instantiation sites

---

## Medium Changes

### 2. [Change Title]

[Same structure as above]

---

## Large Restructuring

### 3. [Change Title]

[Same structure - may be higher level for larger efforts]

---

## Implementation Order

Recommended sequence considering dependencies:

1. [Quick Win 1] - No dependencies
2. [Quick Win 2] - No dependencies
3. [Medium Change 1] - Depends on Quick Win 1
4. [Large Restructuring] - Depends on Medium Change 1

## Risk Assessment

| Change | Risk Level | Mitigation |
| --- | --- | --- |
| [Change 1] | Low | Existing tests cover behavior |
| [Change 2] | Medium | Add integration tests first |
| [Change 3] | High | Feature flag, gradual rollout |

Phase 3: Test Plan

Goal: Design tests that validate refactoring without regressions.

Analysis Steps

  1. Audit existing tests - What's already covered?
  2. Identify gaps - What behavior lacks test coverage?
  3. Design new tests - Focus on integration over unit tests
  4. Minimize mocks - Prefer real dependencies when feasible

Test Philosophy

  • Favor integration tests - Test real interactions between components
  • Use mocks sparingly - Only for external services, not internal dependencies
  • Test behavior, not implementation - Tests should survive refactoring
  • Cover edge cases discovered in research - Use Phase 1 findings

Test Plan Output Format

Write to 03-test-plan.md:

# Test Plan: [Component Name] Refactoring

**Generated**: [Date]
**Based on**: 01-research.md, 02-proposal.md

## Executive Summary

[Overview of testing strategy and coverage goals]

## Current Test Coverage

### Existing Tests

| Test File | Type | Coverage | Notes |
|-----------|------|----------|-------|
| `payment.test.ts` | Unit | Core payment flow | Heavy mocking |
| `checkout.integration.ts` | Integration | Happy path only | No error cases |

### Coverage Gaps

- [ ] Error handling in `processPayment()`
- [ ] Concurrent payment attempts
- [ ] Retry behavior after transient failures

## Test Strategy

### Integration Tests (Preferred)

Tests that exercise real component interactions:

**Test: Payment processing end-to-end**

// tests/integration/payment.test.ts describe('PaymentService', () => { let service: PaymentService; let testDb: TestDatabase;

beforeEach(async () => { testDb = await TestDatabase.create(); service = new PaymentService( new StripeTestGateway(), // Test mode, real API new PaymentRepository(testDb) ); });

it('processes payment and persists record', async () => { const result = await service.processPayment({ amount: 1000, currency: 'usd', customerId: 'cust_123' });

expect(result.status).toBe('succeeded');

const record = await testDb.payments.findById(result.id); expect(record).toBeDefined(); expect(record.amount).toBe(1000); }); });


**Why integration over unit**: Tests real database interactions, actual service coordination, and catches integration bugs that mocks would hide.

### Unit Tests (When Necessary)

Use unit tests with mocks only when:

- External API calls would be slow/costly
- Testing pure business logic in isolation
- Simulating error conditions difficult to reproduce

**Test: Fraud detection logic**

// tests/unit/fraud-detection.test.ts describe('FraudDetector', () => { it('flags high-risk transactions', () => { const detector = new FraudDetector();

const result = detector.assess({ amount: 10000, newCustomer: true, internationalCard: true });

expect(result.riskLevel).toBe('high'); expect(result.requiresReview).toBe(true); }); });


**Why unit here**: Pure logic, no external dependencies, fast execution.

## Tests Per Proposal Change

### For Change 1: [Extract PaymentGateway Interface]

| Test | Type | Purpose |
| --- | --- | --- |
| `gateway-contract.test.ts` | Contract | Verify adapter implements interface correctly |
| `payment-with-mock-gateway.test.ts` | Unit | Verify service works with any gateway |

**New test:**

// tests/contract/payment-gateway.test.ts describe('PaymentGateway contract', () => { const adapters = [ ['Stripe', () => new StripePaymentAdapter(stripeTestClient)], ['Mock', () => new MockPaymentAdapter()], ];

test.each(adapters)('%s adapter implements contract', (name, createAdapter) => { const adapter = createAdapter();

expect(adapter.charge).toBeDefined(); expect(adapter.refund).toBeDefined(); }); });


### For Change 2: [Change Title]

[Similar structure]

## Mock Usage Guidelines

**Acceptable mocks:**

- External payment APIs (Stripe, PayPal)
- Email services
- SMS/notification services
- Third-party APIs with rate limits

**Avoid mocking:**

- Internal services (use real implementations)
- Repositories (use test database)
- Domain logic (test directly)

## Verification Checklist

Before considering refactoring complete:

- All existing tests pass
- New integration tests cover changed behavior
- Edge cases from research are tested
- Error handling paths have coverage
- No increase in mock usage
- CI pipeline green

References

For detailed guidance on each phase:

平台分布

Claude Code

25.45%
按下载量换算24

Gemini CLI

24.51%
按下载量换算23

Antigravity

19.49%
按下载量换算19

Codex

13.44%
按下载量换算13

windsurf

8.02%
按下载量换算8

Cursor

3.4%
按下载量换算3

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

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

继续浏览同类 Skills