Agent skill
refactor_nb
Jupyter Notebook (.ipynb) 内の import 文やコードセルを一括置換・リファクタリングする
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/refactor-nb-tatsuki-washimi-gwexpy
SKILL.md
refactor_notebooks Skill
Jupyter Notebook (.ipynb) ファイルをプログラムから解析し、特定の import パターンやコードの塊をプログラム的に置換・修正するためのスキルです。
Instructions
-
Analyze Notebook Structure:
- Python コードを使用して
.ipynbファイルを JSON としてロードし、cellsリストを走査します。 - 各セルの
cell_typeがcodeであるかを確認します。
- Python コードを使用して
-
Filter and Match:
sourceフィールド(リスト形式)を文字列に結合し、正規表現やキーワードマッチングで対象のセルを特定します。- 特定の import 文 (
from gwexpy.noise import asd) や関数呼び出し、特定のコメントを検索対象にします。
-
Implement Transformation:
- 置換用のスクリプトを作成し、メモリ上でセルの
sourceリストを書き換えます。 - 置換後のソースは、リスト形式(各要素が改行で終わる文字列)にする必要があります。
- 置換用のスクリプトを作成し、メモリ上でセルの
-
Write and Verify:
json.dumpを使用して、インデント 1 (gwexpy での慣習) を保持し、ensure_ascii=Falseを指定してファイルを保存します。- 出力されたノートブックが妥当な JSON であり、意図した通りの変更が行われていることを
view_file等で確認します。
Usage Guidelines
- 多数のノートブックを横断的に修正する場合は、対象ディレクトリ内の
.ipynbをglob等で収集するループスクリプトを作成してください。 - 修正が複雑な場合は、一時的な
.pyスクリプトとして保存し、run_commandで実行してから自身を削除するワークフローを採用してください。
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?