Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问clear审计异常

refactor代码重构

Agent Skill

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

总安装

635

周安装

27

GitHub Stars

23

下载量

222
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/johnlindquist/claude --skill refactor

简介

refactor 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词快速定位结果。

  • 适用于需要基于任务场景或来源线索进行信息筛选的研究检索场景。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用该技能。
  • 安装前需确认权限范围、维护状态,以及是否会触发联网或文件读写操作。
  • 建议结合原始 README 和仓库内容进一步核验具体用法和功能细节。

SKILL.md

Refactoring Assistant

Systematic code refactoring with AI guidance.

Prerequisites

# Gemini for analysis and suggestions
pip install google-generativeai
export GEMINI_API_KEY=your_api_key

# AST-based tools
npm install -g jscodeshift
npm install -g typescript

Refactoring Operations

JavaScript to TypeScript

# Step 1: Rename file
mv file.js file.ts

# Step 2: AI assistance for types
CODE=$(cat file.ts)
gemini -m pro -o text -e "" "Convert this JavaScript to TypeScript with proper types:

$CODE

Requirements:
- Add explicit types for function parameters and returns
- Create interfaces for object shapes
- Use strict TypeScript (no any unless necessary)
- Preserve functionality exactly"

Class to React Hooks

CODE=$(cat ClassComponent.tsx)
gemini -m pro -o text -e "" "Convert this React class component to functional component with hooks:

$CODE

Requirements:
- Convert state to useState
- Convert lifecycle methods to useEffect
- Convert class methods to functions
- Preserve all functionality
- Use proper TypeScript types"

Modernize Code

CODE=$(cat legacy.ts)
gemini -m pro -o text -e "" "Modernize this code to current best practices:

$CODE

Apply:
- ES2023+ features where appropriate
- Modern TypeScript patterns
- Current framework idioms
- Better error handling
- Improved readability"

Systematic Rename

# Using sed for simple renames
find src -name "*.ts" -exec sed -i '' 's/oldName/newName/g' {} +

# Using ripgrep to preview
rg "oldName" src/

# With jscodeshift for AST-safe rename
npx jscodeshift -t rename-transform.ts src/

# AI-assisted rename planning
gemini -m pro -o text -e "" "I want to rename 'oldName' to 'newName' across the codebase.

Files that use it:
$(rg -l "oldName" src/)

Suggest:
1. Order of changes to avoid breaks
2. Any tricky cases to watch for
3. Tests to run after"

Analysis Commands

Find Refactoring Opportunities

gemini -m pro -o text -e "" "Analyze this code for refactoring opportunities:

$(cat src/module.ts)

Look for:
- Code duplication
- Long functions
- Deep nesting
- Magic numbers/strings
- Poor naming
- Missing abstractions
- Tight coupling"

Complexity Analysis

# Find complex functions
rg "function|=>\s*{" src/ -A 50 | head -200

# Ask AI to identify complexity
gemini -m pro -o text -e "" "Identify the most complex functions in this code and suggest simplifications:

$(cat src/complex-file.ts)"

Safe Refactoring Workflow

Step 1: Ensure Test Coverage

# Check coverage before refactoring
npm test -- --coverage

# Identify untested code
npx jest --coverage --coverageReporters=text | grep -E "^(File|.*\|)"

Step 2: Plan the Refactoring

gemini -m pro -o text -e "" "Plan a safe refactoring for:

CURRENT CODE:
$(cat src/file.ts)

GOAL: [what you want to improve]

Provide:
1. Step-by-step plan
2. Risk assessment
3. Rollback strategy
4. Tests to add first"

Step 3: Small, Tested Changes

# Make one small change
# Run tests
npm test

# Commit if green
git add -A && git commit -m "refactor: [specific change]"

# Repeat

Step 4: Verify Behavior

# Compare before/after behavior
# Run integration tests
# Manual testing if needed

Common Refactorings

Extract Function

gemini -m pro -o text -e "" "Extract a reusable function from this code:

$(cat src/file.ts | sed -n '10,50p')

Create a well-named function with:
- Clear parameters
- Typed return value
- JSDoc comment
- Single responsibility"

Simplify Conditionals

gemini -m pro -o text -e "" "Simplify these conditionals:

\`\`\`typescript
$(rg -A 10 "if.*{" src/file.ts)
\`\`\`

Use:
- Early returns
- Guard clauses
- Lookup tables where appropriate
- Optional chaining"

Remove Duplication

# Find similar code
gemini -m pro -o text -e "" "Find duplicate or similar code patterns in:

$(cat src/*.ts)

Suggest how to DRY it up with:
- Shared functions
- Higher-order functions
- Generics if TypeScript"

jscodeshift Transforms

Create Transform

// rename-transform.ts
export default function transformer(file, api) {
  const j = api.jscodeshift;
  return j(file.source)
    .find(j.Identifier, { name: 'oldName' })
    .replaceWith(j.identifier('newName'))
    .toSource();
}

Run Transform

# Dry run
npx jscodeshift -d -p -t transform.ts src/

# Apply
npx jscodeshift -t transform.ts src/

Best Practices

  1. Test first - Don't refactor untested code
  2. Small steps - One change at a time
  3. Commit often - Each working state
  4. Preserve behavior - Refactoring isn't rewriting
  5. Use tools - AST transforms > find-replace
  6. Review diffs - Verify each change
  7. Run tests continuously - Catch breaks early

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

补充不同宿主或平台的使用分布数据

能力 5

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

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

平台分布

Claude Code

28.96%
按下载量换算64

Gemini CLI

23.59%
按下载量换算52

Antigravity

17.36%
按下载量换算39

OpenCode

12.49%
按下载量换算28

windsurf

7.93%
按下载量换算18

Codex

3.34%
按下载量换算7

安全审计

Gen Agent Trust Hub

未通过

Socket

通过

Snyk

未通过

权限和风险

需要联网

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills