mcpField
G
gitnexus-refactoring

gitnexus-refactoring

github.com/mindfold-ai開発15.1k87 回インストール6 週間前に更新
リポジトリ

gitnexus-refactoring について

gitnexus-refactoring は、コード構造を変更する開発者向けの GitNexus スキルです。依存関係や参照の調査から複数ファイルのリネーム、変更範囲の検証までを案内します。

主な機能

  1. 01依存関係と実行フローの把握
  2. 02入出力参照の確認
  3. 03複数ファイルのリネームのプレビューと適用
  4. 04変更ファイルと影響プロセスの検証

活用シーン

  1. 01コードベース全体でのシンボル名変更
  2. 02コードのモジュールへの抽出
  3. 03関数やサービスの分割
  4. 04リファクタリング変更範囲の確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mindfold-ai/trellis --skill gitnexus-refactoring

インストール後、Claude Code で/gitnexus-refactoringを入力して読み込まれたか確認します。

詳細

GitNexus を使ったリファクタリング

使用する場面

  • 「この関数の名前を安全に変更する」
  • 「これをモジュールとして切り出す」
  • 「このサービスを分割する」
  • 「これを新しいファイルに移動する」
  • コードの名前変更、切り出し、分割、再構成を伴うあらゆるタスク

ワークフロー

1. impact({target: "X", direction: "upstream"})  → Map all dependents
2. query({query: "X"})                            → Find execution flows involving X
3. context({name: "X"})                           → See all incoming/outgoing refs
4. Plan update order: interfaces → implementations → callers → tests

「インデックスが古い」と表示された場合 → ターミナルで node .gitnexus/run.cjs analyze を実行してください。

チェックリスト

シンボルの名前変更
- [ ] rename({symbol_name: "oldName", new_name: "newName", dry_run: true}) — preview all edits
- [ ] Review graph edits (high confidence) and ast_search edits (review carefully)
- [ ] If satisfied: rename({..., dry_run: false}) — apply edits
- [ ] detect_changes() — verify only expected files changed
- [ ] Run tests for affected processes
モジュールの切り出し
- [ ] context({name: target}) — see all incoming/outgoing refs
- [ ] impact({target, direction: "upstream"}) — find all external callers
- [ ] Define new module interface
- [ ] Extract code, update imports
- [ ] detect_changes() — verify affected scope
- [ ] Run tests for affected processes
関数/サービスの分割
- [ ] context({name: target}) — understand all callees
- [ ] Group callees by responsibility
- [ ] impact({target, direction: "upstream"}) — map callers to update
- [ ] Create new functions/services
- [ ] Update callers
- [ ] detect_changes() — verify affected scope
- [ ] Run tests for affected processes

ツール

rename — 複数ファイルの名前を自動変更します:

rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
→ 12 edits across 8 files
→ 10 graph edits (high confidence), 2 ast_search edits (review)
→ Changes: [{file_path, edits: [{line, old_text, new_text, confidence}]}]

impact — まずすべての依存先をマッピングします:

impact({target: "validateUser", direction: "upstream"})
→ d=1: loginHandler, apiMiddleware, testUtils
→ Affected Processes: LoginFlow, TokenRefresh

detect_changes — リファクタリング後に変更を検証します:

detect_changes({scope: "all"})
→ Changed: 8 files, 12 symbols
→ Affected processes: LoginFlow, TokenRefresh
→ Risk: MEDIUM

cypher — カスタム参照クエリ:

MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
RETURN caller.name, caller.filePath ORDER BY caller.filePath

リスクに関するルール

リスク要因対策
呼び出し元が多い(>5)自動更新には rename を使用します
領域をまたぐ参照スコープの検証に、後から detect_changes を使用します
文字列/動的な参照見つけるには query を使用します
外部/パブリック API適切にバージョン管理し、非推奨にします

例:validateUser を authenticateUser に名前変更する

1. rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
   → 12 edits: 10 graph (safe), 2 ast_search (review)
   → Files: validator.ts, login.ts, middleware.ts, config.json...

2. Review ast_search edits (config.json: dynamic reference!)

3. rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: false})
   → Applied 12 edits across 8 files

4. detect_changes({scope: "all"})
   → Affected: LoginFlow, TokenRefresh
   → Risk: MEDIUM — run tests for these flows

コメント