Token导航 LogoToken导航

Agent Skill · 研究检索

refactoring-code(重构代码)

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

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

总安装 419周安装 18GitHub Stars 5下载 147核验 2026-05-01

安装说明

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

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/third774/dotfiles --skill refactoring-code

这个 Skill 是做什么的

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

refactoring-code 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。适用于单文件或多文件重构前的相似代码模式查找、命名规范统一或注释补充。基于关键词返回代码片段、风格指南或重构模板供参考。

安装命令:npx skills add https://github.com/third774/dotfiles --skill refactoring-code。注意部分技能可能依赖特定编辑器插件,需核对宿主环境兼容性。

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

上手步骤

4 步
  1. 1

    确认自己的宿主工具

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

  2. 2

    拿到安装命令

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

  3. 3

    安装后重启宿主

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

  4. 4

    按最小权限试用

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

常见问题

6 条

refactoring-code 怎么安装?

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

refactoring-code 支持哪些 AI 工具?

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

refactoring-code 需要什么权限?

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

refactoring-code 是免费的吗?

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

refactoring-code 用的人多吗?

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

refactoring-code 安全吗?

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

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

值得选的地方

  • 同时适配 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调用外部服务未明确有提醒
refactoring-code

重构代码 · 本页

4195接触敏感数据MIT通过

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

SKILL.md 原文

Refactoring Code

You are following a systematic refactoring methodology that improves code quality, maintainability, and simplicity while preserving existing behavior.

Core Principle: Refactoring changes structure, not functionality. Safety and clarity are more important than elegance.

The Iron Law

BEHAVIOR MUST BE PRESERVED
Tests must verify behavior, not implementation

If you change what the code does (not just how it does it), you're not refactoring—you're rewriting.

Prerequisites

  • Access to codebase for pattern research
  • Behavior-driven tests that verify current functionality
  • Understanding of project conventions

Core Responsibilities

  1. Simplify Complex Code - Break down complex functions, reduce nesting, improve readability
  2. Extract Patterns - Identify and extract reusable components, hooks, utilities
  3. Eliminate Duplication - Apply DRY principles while avoiding premature abstraction
  4. Improve Type Safety - Strengthen TypeScript usage, eliminate any types when possible
  5. Performance Optimization - Identify unnecessary re-renders, optimize data structures
  6. Align with Standards - Ensure code follows project patterns and conventions

The Five-Phase Refactoring Process

You MUST complete each phase before proceeding to the next.

Copy this checklist and track your progress:

Refactoring Progress:
- [ ] Phase 1: Understand Current Behavior
  - [ ] Read existing code thoroughly
  - [ ] Check usage across codebase
  - [ ] Document current behavior
- [ ] Phase 2: Verify Test Coverage (CRITICAL)
  - [ ] Behavior-driven tests exist and pass
  - [ ] Tests cover main workflows and edge cases
  - [ ] Tests don't depend on implementation details
- [ ] Phase 3: Identify Issues
  - [ ] Issues documented with locations
  - [ ] Issues categorized by type and severity
  - [ ] Root cause understood for each issue
- [ ] Phase 4: Plan Refactoring
  - [ ] Broken into small, verifiable steps
  - [ ] Each step has verification criteria
  - [ ] Dependencies between steps identified
- [ ] Phase 5: Execute & Verify
  - [ ] All planned changes implemented
  - [ ] All tests pass
  - [ ] No new type errors or warnings
  - [ ] Behavior verified unchanged

Phase 1: Understand Current Behavior

Objective: Know exactly what the code does before changing how it does it.

  1. Read existing code thoroughly

- Understand the purpose, not just the implementation - Identify inputs, outputs, and side effects - Note any edge cases or error handling

  1. Check usage across codebase

- Use Grep to find all call sites - Understand how consumers depend on this code - Identify any public APIs that must remain stable

  1. Document current behavior

- List what the code accomplishes - Note any implicit contracts or assumptions - Identify performance characteristics if relevant

Phase 1 Complete When:

  • You can explain what the code does in plain language
  • All call sites and dependencies are identified
  • Current behavior is documented

Phase 2: Verify Test Coverage (CRITICAL)

Objective: Ensure behavior-driven tests exist that will catch regressions.

BEFORE refactoring, ensure tests verify BEHAVIOR (what users see/do), NOT implementation:

✅ Good - Behavior-driven tests:

// Tests user-observable behavior
test('displays error message when API returns 404', async () => {
  server.use(
    http.get('/api/users', () => new HttpResponse(null, { status: 404 }))
  );
  render(<UserList />);
  expect(await screen.findByText(/user not found/i)).toBeInTheDocument();
});

❌ Bad - Implementation-detail tests:

// Tests internal state/functions - breaks during refactoring
test('sets error state when fetch fails', () => {
  const wrapper = shallow(<UserList />);
  wrapper.instance().handleError(new Error('404'));
  expect(wrapper.state('error')).toBe('404');
});

Test Quality Checklist:

  • Tests verify user workflows, not function calls
  • Tests use real dependencies (not mocks of components)
  • Tests query by role/label/text, not internal state
  • Tests will survive refactoring when behavior unchanged

If tests are missing or test implementation details:

  1. Add behavior-driven tests first (see writing-tests skill)
  2. Focus on user workflows, loading/error states, interactions
  3. Ensure new tests are passing before refactoring

Why this matters: Unit tests checking internal state break during refactoring even when behavior is unchanged. Behavior-driven tests prove the feature works before and after.

Phase 2 Complete When:

  • Behavior-driven tests exist and pass
  • Tests cover main workflows and edge cases
  • Tests don't depend on implementation details

Phase 3: Identify Issues

Objective: Systematically catalog what needs improvement.

Common refactoring opportunities:

Issue TypeIndicatorsImpact
ComplexityDeep nesting (>3 levels), long functions (>50 lines), many parameters (>4)Hard to understand, error-prone
DuplicationCopy-pasted code, repeated patterns, similar logic in multiple placesMaintenance burden, inconsistent fixes
Poor NamingUnclear variables (x, data, temp), misleading names, inconsistent terminologyCognitive overhead
Type Safety Gapsany types, missing types, type assertions, implicit anyRuntime errors, poor IDE support
Performance IssuesUnnecessary re-renders, inefficient algorithms (O(n²) when O(n) possible), large bundle sizeSlow UX, high resource usage
Pattern ViolationsInconsistent with project conventions, outdated patternsTeam confusion, tech debt

Analysis checklist:

  • Identify specific complexity hotspots
  • Catalog duplicated code blocks
  • List unclear or misleading names
  • Find type safety vulnerabilities
  • Measure performance bottlenecks (if applicable)
  • Check against project conventions

Phase 3 Complete When:

  • All issues are documented with locations
  • Issues are categorized by type and severity
  • You understand the root cause of each issue

Phase 4: Plan Refactoring

Objective: Create a safe, incremental execution plan.

  1. Create todo list for multi-step refactorings (use TodoWrite tool)

- Break large refactorings into small, verifiable steps - Each step should be independently testable

  1. Prioritize changes by impact and risk

- High impact, low risk first (e.g., rename variables) - Defer high-risk changes (e.g., algorithm rewrites)

  1. Consider backward compatibility

- If this is a public API, can we deprecate gradually? - Do we need to support both old and new interfaces temporarily?

  1. Plan verification steps

- What will you check after each change? - Which tests must pass?

Example refactoring breakdown:

**Large task:** Extract user authentication logic into reusable hook

**Breakdown:**
1. Create new hook file with basic structure
2. Move authentication state management to hook
3. Move login/logout handlers to hook
4. Extract token refresh logic
5. Replace inline logic in components with hook calls
6. Remove old duplicated code
7. Add tests for hook

Phase 4 Complete When:

  • Refactoring is broken into small steps
  • Each step has clear verification criteria
  • Dependencies between steps are identified
  • Risk mitigation strategies are planned

Phase 5: Execute & Verify

Objective: Make changes safely with continuous verification.

Execution principles:

  1. Make one change at a time

- Single responsibility per edit - Commit frequently if using git

  1. Run tests after each change

- Don't accumulate untested changes - Catch regressions immediately

  1. Check TypeScript compilation

- tsc --noEmit or equivalent - Fix type errors before proceeding

  1. Verify behavior unchanged

- Run the application manually if needed - Confirm user-facing behavior is identical

Verification checklist per step:

  • Tests pass (npm test or equivalent)
  • TypeScript compiles without errors
  • No new linting warnings
  • Behavior manually verified (if high-risk change)

If something breaks:

  • STOP immediately
  • Use systematic-debugging skill to investigate
  • Don't proceed until root cause is understood
  • Consider reverting if fix is unclear

Phase 5 Complete When:

  • All planned changes are implemented
  • All tests pass
  • No new type errors or warnings
  • Code follows project conventions
  • Behavior is verified unchanged

Red Flags - STOP and Reassess

If you catch yourself:

  • Changing behavior while refactoring → You're rewriting, not refactoring. Separate behavior changes from refactoring.
  • "I'll just skip the tests this time" → Tests are your safety net. No tests = no safe refactoring.
  • Adding complexity to remove complexity → Over-engineering. Simpler solution probably exists.
  • "This is clever!" → Code should be clear, not clever. Clever code is hard to maintain.
  • Removing comments that explained context → Comments explaining "why" are valuable. Keep them.
  • Breaking existing APIs without considering consumers → Check all call sites. Plan deprecation if needed.
  • Abstracting before seeing pattern 3 times → Rule of Three: Don't abstract until you see the pattern repeated three times.

ALL of these mean: STOP. Reassess your approach.

React/TypeScript Patterns

For TypeScript/React projects, see references/react-typescript.md for component structure, type safety patterns, and refactoring checklists.

Common Refactoring Patterns - Quick Reference

SmellRefactoringExample
Long functionExtract smaller functionsSplit 100-line function into 5 focused functions
Duplicate codeExtract to shared utilityCreate formatCurrency() instead of inline formatting
Deep nestingEarly returns, guard clausesReplace if/else pyramid with early returns
Magic numbersNamed constantsconst MAX_RETRIES = 3 instead of hardcoded 3
Large componentSplit into smaller componentsExtract <UserProfile> from <Dashboard>
Complex conditionExtract to named functionisEligibleForDiscount() instead of if (user.age > 65 && user.isPremium &&...)
Primitive obsessionCreate type/interfacetype Email = string with validation instead of raw strings
Long parameter listParameter objectPass {user, options, config} instead of 8 parameters

Integration with Other Skills

This skill requires using:

  • writing-tests - REQUIRED when adding behavior-driven tests before refactoring
  • systematic-debugging - REQUIRED when refactoring breaks tests unexpectedly

Complementary skills:

  • verification-before-completion - Use before claiming refactoring is complete
  • testing-anti-patterns - Avoid when writing tests for refactored code

When to Stop Refactoring

You've refactored enough when:

  • ✅ Code is clear and easy to understand
  • ✅ Duplication is eliminated (without over-abstraction)
  • ✅ Types are explicit and safe
  • ✅ Tests pass and coverage is maintained
  • ✅ Code follows project conventions
  • ✅ Team members can understand the code without explanation

Don't refactor further if:

  • You're making code "elegant" but harder to understand
  • You're abstracting before seeing the pattern 3 times
  • You're refactoring code that works well and won't change soon
  • You're optimizing performance without measuring first

Communication

When proposing refactorings:

  1. Explain what problems you're solving

- "This function is 150 lines and does 5 different things" - Not just "This code could be better"

  1. Show before/after comparisons

- Demonstrate the improvement concretely - Highlight reduced complexity metrics

  1. Highlight risks and breaking changes

- "This changes the public API" - "Consumers will need to update imports"

  1. Suggest incremental steps for large refactorings

- "We can do this in 3 phases over 2 weeks" - Make large changes less scary

  1. Challenge your own assumptions

- "Is this really better, or just different?" - "Am I solving a real problem?"

Key Principles Summary

  1. Preserve behavior - Tests must verify same outcomes before and after
  2. Test first - Behavior-driven tests are your safety net
  3. Small steps - One change at a time, verify continuously
  4. Clarity over cleverness - Code should be obvious, not impressive
  5. Rule of Three - Don't abstract until you see the pattern three times
  6. Safety over elegance - Working code is better than beautiful code

Remember: The goal of refactoring is to make future changes easier, not to make code perfect.

平台分布

windsurf

26.73%
按下载量换算39

OpenCode

25.49%
按下载量换算37

Codex

19.84%
按下载量换算29

Claude Code

13.7%
按下载量换算20

Antigravity

8.66%
按下载量换算13

Gemini CLI

3.22%
按下载量换算5

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

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

安装前确认

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

继续浏览同类 Skills