本文へスキップ
Skillpedia
一般的なプログラミング70k · #3137

refactor

できること

このツールは、コードを整理して改善する作業を支援します。何を変更したいのかを理解し、コード同士のつながりを分析して、エラーを避けるように安全に変更を計画します。

使う場面

  • ✓複雑なコードを簡潔にしたいとき。
  • ✓コードの一部を新しいモジュールに切り出す必要があるとき。
  • ✓古いプロジェクトを最新化したり、構造を組み直したりしたいとき。

スキルのリンク

https://github.com/code-yeongyu/oh-my-openagent/blob/dev/packages/shared-skills/skills/refactor/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/code-yeongyu/oh-my-openagent/blob/dev/packages/shared-skills/skills/refactor/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“ログイン関数を、新しい認証パターンを使うようにリファクタリングしてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

AIはまずリクエスト内容を理解し、すべてのコードを分析して各部分の関係を把握します。次に詳細な計画を立て、動作し続けていることを確認しながら、変更を一つずつ段階的に行います。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

export const REFACTOR_TEMPLATE = `# Intelligent Refactor Command

Usage

``` /refactor <refactoring-target> [--scope=<file|module|project>] [--strategy=<safe|aggressive>]

Arguments: refactoring-target: What to refactor. Can be: - File path: src/auth/handler.ts - Symbol name: "AuthService class" - Pattern: "all functions using deprecated API" - Description: "extract validation logic into separate module"

Options: --scope: Refactoring scope (default: module) - file: Single file only - module: Module/directory scope - project: Entire codebase

--strategy: Risk tolerance (default: safe) - safe: Conservative, maximum test coverage required - aggressive: Allow broader changes with adequate coverage ```

What This Command Does

Performs intelligent, deterministic refactoring with full codebase awareness. Unlike blind search-and-replace, this command:

  1. Understands your intent - Analyzes what you actually want to achieve
  2. Maps the codebase - Builds a definitive codemap before touching anything
  3. Assesses risk - Evaluates test coverage and determines verification strategy
  4. Plans meticulously - Creates a detailed plan with Plan agent
  5. Executes precisely - Step-by-step refactoring with LSP and AST-grep
  6. Verifies constantly - Runs tests after each change to ensure zero regression

PHASE 0: INTENT GATE (MANDATORY FIRST STEP)

BEFORE ANY ACTION, classify and validate the request.

Step 0.1: Parse Request Type

Signal Classification Action
Specific file/symbol Explicit Proceed to codebase analysis
"Refactor X to Y" Clear transformation Proceed to codebase analysis
"Improve", "Clean up" Open-ended MUST ask: "What specific improvement?"
Ambiguous scope Uncertain MUST ask: "Which modules/files?"
Missing context Incomplete MUST ask: "What's the desired outcome?"

Step 0.2: Validate Understanding

Before proceeding, confirm:

  • Target is clearly identified
  • Desired outcome is understood
  • Scope is defined (file/module/project)
  • Success criteria can be articulated

If ANY of above is unclear, ASK CLARIFYING QUESTION:

``` I want to make sure I understand the refactoring goal correctly.

What I understood: [interpretation] What I'm unsure about: [specific ambiguity]

Options I see:

  1. [Option A] - [implications]
  2. [Option B] - [implications]

My recommendation: [suggestion with reasoning]

Should I proceed with [recommendation], or would you prefer differently? ```

Step 0.3: Create Initial Todos

IMMEDIATELY after understanding the request, create todos:

``` TodoWrite([ {"id": "phase-1", "content": "PHASE 1: Codebase Analysis - launch parallel explore agents", "status": "pending", "priority": "high"}, {"id": "phase-2", "content": "PHASE 2: Build Codemap - map dependencies and impact zones", "status": "pending", "priority": "high"}, {"id": "phase-3", "content": "PHASE 3: Test Assessment - analyze test coverage and verification strategy", "status": "pending", "priority": "high"}, {"id": "phase-4", "content": "PHASE 4: Plan Generation - invoke Plan agent for detailed refactoring plan", "status": "pending", "priority": "high"}, {"id": "phase-5", "content": "PHASE 5: Execute Refactoring - step-by-step with continuous verification", "status": "pending", "priority": "high"}, {"id": "phase-6", "content": "PHASE 6: Final Verification - full test suite and regression check", "status": "pending", "priority": "high"} ]) ```


PHASE 1: CODEBASE ANALYSIS (PARALLEL EXPLORATION)

Mark phase-1 as in_progress.

1.1: Launch Parallel Explore Agents (BACKGROUND)

Fire ALL of these simultaneously using `call_omo_agent`:

``` // Agent 1: Find the refactoring target call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find all occurrences and definitions of [TARGET]. Report: file paths, line numbers, usage patterns." )

// Agent 2: Find related code call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find all code that imports, uses, or depends on [TARGET]. Report: dependency chains, import graphs." )

// Agent 3: Find similar patterns call_omo_agent( subagent_type="explore", run_in_background=true, prompt="Find similar code patterns to [TARGET] in the codebase.

…

よくある質問

「リファクタリング」とはどういう意味ですか?

既存のコードの動作は変えずに、より見やすく、効率的に、または理解しやすくするために構成を整理することです。

AIはどうやって何も壊さないようにしていますか?

既存のテストのカバレッジを分析し、小さな変更を加えるたびにテストを実行して、何も壊れていない(リグレッションがない)ことを確認します。

ファイル全体と一部のどちらをリファクタリングするよう頼めますか?

はい。単一のファイル、モジュール(ディレクトリ)、またはプロジェクト全体のどれを対象にするかを指定できます。

詳細

作者による元の説明

Guides a refactor, cleanup, or restructure with the right decomposition. Use when the user asks to refactor, simplify, extract, or modernize code.

repo: code-yeongyu/oh-my-openagent

人気

GitHubのスター
70k
ランキング
#3137
ライセンス
NOASSERTION
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル