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

refac-module-to-subpackagerefac 模块到子包

Agent Skill

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

总安装

198

周安装

8

GitHub Stars

81

下载量

62
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/dagster-io/erk --skill refac-module-to-subpackage

简介

用于查找和筛选与代码重构相关的信息。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

  • 适合在模块拆分或包结构调整场景中定位方案。
  • 需结合具体项目结构和依赖关系进行验证。
  • 使用前请确认是否会触发代码修改或文件重命名操作。
  • refac-module-to-subpackage 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Module to Subpackage

Convert a monolithic Python module into a subpackage with submodules while preserving all behavior. This is a pure mechanical reorganization — no logic changes, no fixes to pre-existing issues, no improvements.

Core Principle: Pure Reorg

This refactoring must be behavior-preserving. Copy code verbatim. Do not:

  • Fix pre-existing lint/style issues (they'll show up in review — resolve as "pre-existing")
  • Rename functions or change signatures
  • "Improve" code while moving it
  • Add or remove functionality

The goal is a clean diff that only moves code between files. Reviewers should be able to verify the split is correct by confirming every line in the old file appears in exactly one new file.

Phase 1: Structural Inventory

Understand the monolith before designing the split.

Scan for boundaries:

# Section headers and definitions with line numbers
grep -n "^# ==\|^class \|^def " <file>

Capture:

  • All section comment blocks (these are natural split boundaries)
  • All class definitions and their line ranges
  • All top-level function definitions
  • All imports at the top of the file
  • Total count of top-level definitions (classes + functions)
  • Any module-level helpers or constants

Why this matters: Section headers placed by the original author reveal the intended logical grouping. Classes and functions without headers between them likely belong together.

Phase 2: Target Discovery

Check if the destination already has structure.

Check for existing subpackage:

# If splitting foo.py, check for foo/ directory
ls <target_directory>/

Determine:

  • Does the target directory already exist? (common for test files)
  • Are there existing files that overlap with planned new files?
  • Is there an __init__.py? (required for test directories in this project)
  • What patterns do existing files in the directory follow?

If existing files overlap: You'll need to merge in Phase 5 rather than create fresh.

Phase 3: Grouping Design

Map sections of the monolith to new files. Present this as a table for user review before proceeding.

Grouping heuristics (in priority order):

  1. Author's sections — Comment headers like # === Tests for Foo === are the strongest signal
  2. Feature cohesion — Code testing/implementing the same feature belongs together
  3. Import cohesion — Code sharing the same specialized imports likely belongs together
  4. Size balance — Avoid files with fewer than ~20 lines (merge with a neighbor) or more than ~500 lines (split further)

File naming: Match the concept being grouped, not the original file name.

  • test_capabilities.pytest_workflows.py, test_permissions.py, test_registry.py
  • utils.pystring_utils.py, path_utils.py, date_utils.py

Present a mapping table:

New fileSections (line ranges)What it contains~Lines
test_base.pyCapabilityResult (47-58),...Core data structures~100
............

Phase 4: Shared Code Placement

Identify code used across multiple sections and decide where it lives.

Types of shared code:

  • Helper functions (e.g., _write_state_toml())
  • Helper classes (e.g., _TestCapability)
  • Constants and fixtures
  • Module-level configuration

Placement rules:

  • 1 consumer → place in that consumer's file
  • 2 consumers → place in the primary consumer's file (the one that uses it more)
  • 3+ consumers → consider a _helpers.py or conftest.py (for test fixtures), but only if truly necessary. Duplication across 2-3 files is often preferable to an artificial shared module.

Phase 5: Execution

Create new files

For each file in the mapping:

  1. Write the module docstring (brief, describes what this file tests/contains)
  2. Add only the imports needed by the functions in this file
  3. Copy the functions/classes verbatim from the monolith
  4. Preserve section comment headers within the file

Merge into existing files

When a target file already exists:

  1. Read the existing file completely
  2. Compare tests/functions by behavior, not by name — two functions testing the same thing with different names are duplicates
  3. Append only non-duplicate code to the end of the existing file
  4. Add appropriate section headers to separate old and new content

Fix mechanical issues

After creating all files:

# Fix import sorting (the most common issue after splitting)
uv run ruff check --fix <new_files>

Delete the original

Only after all new files are created and verified:

rm <original_monolith.py>

Phase 6: Verification

Count definitions:

# Before (from git history or memory)
grep -c "^def \|^class " <original_file>

# After (across all new files)
grep -rch "^def \|^class " <new_files> | paste -sd+ - | bc

The after count should equal or exceed the before count (excess comes from pre-existing files that were merged into).

Check for dangling references:

# Ensure nothing imports or references the deleted file
grep -r "<original_module_name>" <project_root>

Run tests and linter (use devrun agent):

  • Run the test suite for the affected directory
  • Run linter checks
  • Run type checker

Phase 7: PR Workflow

Pure reorg discipline

When review comments flag issues in the moved code:

  • If the issue existed in the original file → resolve as pre-existing
  • Reply: "Pre-existing: this [issue] was copied verbatim from the original <file>. Not addressing in this pure reorg PR."
  • Then resolve the thread

Load the pr-operations skill (@.claude/skills/pr-operations/) for correct thread resolution commands. Key points:

  • Use erk exec get-pr-review-comments to fetch threads with proper thread IDs
  • Use erk exec resolve-review-thread --thread-id <PRRT_id> --comment "..." to reply AND resolve
  • Use erk exec resolve-review-threads for batch resolution
  • Never use raw gh api for thread operations (replies without resolving)

Commit message

Format: Split <module> into <subpackage> subpackage (#<PR>)

The PR description should include:

  • The mapping table from Phase 3
  • Before/after definition counts
  • Note that this is a pure reorg with no behavior changes

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

35.91%
按下载量换算22

Claude

27.93%
按下载量换算17

Cursor

17.2%
按下载量换算11

Gemini CLI

10.13%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

可疑

Snyk

通过

权限和风险

需要联网

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

安装前确认

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

来源信息

继续浏览同类 Skills