Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

refactor代码重构

Agent Skill

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

总安装

315

周安装

13

GitHub Stars

1,724

下载量

103
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

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

简介

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

  • 适用于关键词搜索、任务场景匹配或来源线索筛选等研究检索场景。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用该技能。
  • 安装前需确认权限范围、维护状态及是否触发联网或文件操作。
  • 建议结合原始 README 和仓库路径进一步核验具体用法和功能边界。

SKILL.md

Large-Scale Refactoring

Perform codebase-wide refactors using AST-aware tools for accuracy and safety. This skill emphasizes scripted approaches over individual file edits and integrates with the gameplan workflow for complex changes.

When to Use

  • Renaming symbols (functions, types, variables) across multiple files
  • Pattern replacements (e.g., updating API calls, changing import paths)
  • Function signature changes that affect many call sites
  • Migrating from one API/pattern to another
  • Removing deprecated code paths
  • Consistent style/naming transformations

Complexity Assessment

Before starting, assess the refactor complexity:

ComplexityFiles AffectedPatternsApproach
Simple< 20 filesSingle patternDirect ast-grep execution
Medium20-100 filesMultiple patternsScripted approach with verification
Complex100+ files, behavioral changesMultiple patterns, tests affectedCreate a gameplan first

Complex refactors involving architectural changes, multi-step migrations, or behavioral modifications should use the gameplan workflow. See platform/flowglad-next/llm-prompts/new-gameplan.md for the template.

Core Principles

  1. Understand scope BEFORE making changes - Search and count affected files before executing replacements
  2. Work at AST level - Default to ast-grep for syntax-aware matching (per CLAUDE.md guidance)
  3. Verify after changes - Always run bun run check after refactoring
  4. Prefer idempotent transformations - Running the same refactor twice should produce the same result
  5. For complex refactors - Use multi-patch strategy with [INFRA] patches shipping first

Tool Selection

Prefer tools higher in this hierarchy:

PriorityToolBest ForReference
1ast-grepMost TypeScript refactoring (search + replace)ast-grep-patterns.md
2ts-morphType-aware transforms requiring TypeScript compiler APItools-reference.md
3jscodeshiftLeveraging existing codemodstools-reference.md
4combySimple structural patternstools-reference.md
5ESLint --fixEnforcing patterns via rulestools-reference.md
6sed/awkSimple text-only replacementstools-reference.md
7Individual editsFallback when scripted approaches fail-

See tools-reference.md for detailed usage of each tool.

Simple Refactor Workflow

For refactors affecting < 100 files with a single pattern:

Step 1: Understand the Scope

# Count affected files
ast-grep --lang typescript -p 'oldFunctionName($$$ARGS)' --json | jq length

# Preview matches with context
ast-grep --lang typescript -p 'oldFunctionName($$$ARGS)' -r 'newFunctionName($$$ARGS)' --interactive

Step 2: Create a Checkpoint

# Ensure clean working directory
git status

# Create a checkpoint commit or stash if needed
git stash push -m "pre-refactor checkpoint"

Step 3: Execute the Refactor

# Apply the transformation
ast-grep --lang typescript -p 'oldFunctionName($$$ARGS)' -r 'newFunctionName($$$ARGS)' --update-all

Step 4: Verify Changes

# Check for type errors and lint issues
bun run check

# Review the diff
git diff --stat
git diff

Step 5: Handle Edge Cases

Some matches may require manual attention:

  • Dynamic references (e.g., obj[funcName])
  • String literals containing the pattern
  • Comments and documentation

Step 6: Run Tests

# Run affected tests
bun run test:backend

Step 7: Commit

git add -A
git commit -m "refactor: rename oldFunctionName to newFunctionName

Co-Authored-By: Claude <noreply@anthropic.com>"

Complex Refactor Workflow

For refactors involving 100+ files, behavioral changes, or architectural modifications:

Step 1: Create a Gameplan

Use the gameplan template at platform/flowglad-next/llm-prompts/new-gameplan.md. The gameplan should include:

  • Problem Statement: What we're changing and why
  • Current State Analysis: How the code currently works
  • Required Changes: Specific files, functions, and transformations
  • Acceptance Criteria: What "done" looks like
  • Patches: Ordered list of incremental changes

Step 2: Follow Multi-Patch Strategy

Organize patches by classification:

ClassificationDescriptionWhen to Ship
[INFRA]No observable behavior change (types, helpers, test stubs)Ship early
[GATED]New behavior behind feature flagShip before activation
[BEHAVIOR]Changes observable behaviorShip last, keep small

Goal: Maximize [INFRA] and [GATED] patches. Ship non-functional changes first to enable early review and reduce risk.

Step 3: Test-First Pattern

Write test stubs with .skip markers BEFORE implementation:

describe('newApiCall', () => {
  it.skip('should return the expected shape', async () => {
    // PENDING: Patch 3
    // setup: create test data
    // expectation: returns { id, name, status }
  })
})

Implement and unskip tests in the same patch as the code being tested.

Step 4: Execute Patches in Order

For each patch:

  1. Read the patch specification from the gameplan
  2. Execute the changes (prefer ast-grep/ts-morph over manual edits)
  3. Run bun run check
  4. Run tests (bun run test:backend)
  5. Commit with patch reference

Common Refactoring Patterns

Rename a Function

# Find all usages
ast-grep --lang typescript -p 'oldName($$$ARGS)'

# Replace
ast-grep --lang typescript -p 'oldName($$$ARGS)' -r 'newName($$$ARGS)' --update-all

Rename a Type

# Find type usages
ast-grep --lang typescript -p ': OldType'
ast-grep --lang typescript -p 'OldType<$T>'

# Replace (run both)
ast-grep --lang typescript -p ': OldType' -r ': NewType' --update-all
ast-grep --lang typescript -p 'OldType<$T>' -r 'NewType<$T>' --update-all

Change Function Signature (Add Parameter)

# Find calls to update
ast-grep --lang typescript -p 'myFunc($ARG1, $ARG2)'

# Add new parameter with default
ast-grep --lang typescript -p 'myFunc($ARG1, $ARG2)' -r 'myFunc($ARG1, $ARG2, { newOption: false })' --update-all

Update Import Paths

# Find imports from old path
ast-grep --lang typescript -p "import { $$$IMPORTS } from '@/old/path'"

# Update to new path
ast-grep --lang typescript -p "import { \$\$\$IMPORTS } from '@/old/path'" -r "import { \$\$\$IMPORTS } from '@/new/path'" --update-all

Remove Deprecated Function Calls

# Find and remove deprecated calls
ast-grep --lang typescript -p 'deprecatedInit()' -r '' --update-all

See ast-grep-patterns.md for more patterns.

Verification Checklist

After any refactor:

  • bun run check passes (types and lint)
  • git diff --stat shows expected file count
  • No unintended changes (review diff carefully)
  • Tests pass (bun run test:backend)
  • Edge cases handled (string literals, dynamic references, comments)

Reference Documentation

  • ast-grep-patterns.md - Pattern library and metavariable syntax
  • tools-reference.md - Detailed tool comparison and usage
  • platform/flowglad-next/llm-prompts/new-gameplan.md - Gameplan template for complex refactors

Example: Full Refactor Session

Rename createBillingRun to initiateBillingRun across the codebase:

# 1. Scope the change
ast-grep --lang typescript -p 'createBillingRun' --json | jq length
# Output: 47

# 2. Preview the transformation
ast-grep --lang typescript -p 'createBillingRun($$$ARGS)' -r 'initiateBillingRun($$$ARGS)'

# 3. Apply the change
ast-grep --lang typescript -p 'createBillingRun($$$ARGS)' -r 'initiateBillingRun($$$ARGS)' --update-all

# 4. Handle the function definition separately
ast-grep --lang typescript -p 'const createBillingRun = $BODY' -r 'const initiateBillingRun = $BODY' --update-all

# 5. Update type annotations if any
ast-grep --lang typescript -p 'typeof createBillingRun' -r 'typeof initiateBillingRun' --update-all

# 6. Verify
bun run check

# 7. Review
git diff --stat
git diff

# 8. Test
bun run test:backend

# 9. Commit
git add -A
git commit -m "refactor: rename createBillingRun to initiateBillingRun

Renamed for clarity - 'initiate' better describes the action of
starting a billing run process.

Co-Authored-By: Claude <noreply@anthropic.com>"

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

35.62%
按下载量换算37

Claude

30.71%
按下载量换算32

Cursor

20.02%
按下载量换算21

Gemini CLI

8.86%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills