Agent skill
refactor_nb
Jupyter Notebook (.ipynb) 内のコード要素を一括置換・リファクタリングする
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/refactor-nb
SKILL.md
refactor_notebooks Skill
This skill is for programmatically analyzing Jupyter Notebook (.ipynb) files and performing batch replacement or modification of specific import patterns or code blocks.
Instructions
-
Analyze Notebook Structure:
- Load
.ipynbfiles as JSON using Python and iterate through thecellslist. - Verify if the
cell_typeof each cell iscode.
- Load
-
Filter and Match:
- Join the
sourcefield (list format) into a string and use regular expressions or keyword matching to identify target cells. - Target specific import statements (e.g.,
from gwexpy.noise import asd), function calls, or targeted comments.
- Join the
-
Implement Transformation:
- Create a transformation script to rewrite the
sourcelist of the cells in memory. - The updated source must be in list format (each element as a string ending with a newline).
- Create a transformation script to rewrite the
-
Write and Verify:
- Save the file using
json.dump, maintaining an indent of 1 (agwexpyconvention) and specifyingensure_ascii=False. - Verify that the resulting notebook is valid JSON and that the intended changes have been applied using
view_fileor similar.
- Save the file using
Usage Guidelines
- When modifying multiple notebooks across a directory, create a loop script that collects
.ipynbfiles usingglobor similar. - For complex refactoring, adopt a workflow of saving the logic as a temporary
.pyscript, executing it viarun_command, and then deleting the script.
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?