Token导航 LogoToken导航

Agent Skill · 研究检索

python-refactor(Python refactor 搜索)

用于辅助 Python 项目开发、测试、依赖管理和常见框架工作流。它适合让 Agent 阅读 Python 代码、定位测试问题、整理运行命令、生成脚本或分析数据处理逻辑。使用时需要确认项目虚拟环境、依赖版本和测试入口;涉及执行脚本、读写文件、访问数据库或调用外部 API 时,应先明确运行目录和输入输出范围,避免误改生产数据。

python-refactor 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 25,945。

总安装 3,669周安装 147GitHub Stars 1下载 1,188核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

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

请帮我安装这个 Agent Skill:python-refactor(Python refactor 搜索)
来源仓库:https://github.com/acaprino/alfio-claude-plugins
仓库路径:skills/python-refactor
安装命令:
npx skills add https://github.com/acaprino/alfio-claude-plugins --skill python-refactor
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/acaprino/alfio-claude-plugins --skill python-refactor

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

协助 Python 代码的重构和架构优化工作。适用于技术演进或性能提升驱动的代码改造需求。提供函数拆分、依赖解耦和设计模式应用建议。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。重大重构前应建立完整的回归测试套件确保稳定性。

python-refactor 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/python-refactor

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/acaprino/alfio-claude-plugins --skill python-r…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

python-refactor 怎么安装?

在终端执行 npx skills add https://github.com/acaprino/alfio-claude-plugins --skill python-refactor。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

python-refactor 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

python-refactor 需要什么权限?

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

python-refactor 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

python-refactor 用的人多吗?

公开数据是累计安装 3,669 次,近一周安装 147 次,下载 1,188 次,GitHub 1 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

python-refactor 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
python-refactor

Python refactor 搜索 · 本页

3,6691需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Python Refactor

Transform complex Python into clear, maintainable code while preserving correctness. Phased workflow with safety-by-design and continuous validation. For deep references (anti-patterns, OOP principles, cognitive complexity, regression prevention), see the references/ directory.

When to invoke

  • Explicit "human", "readable", "maintainable", "clean", or "refactor" request
  • Code review flags comprehension or maintainability issues
  • Legacy code modernization
  • Onboarding / educational contexts
  • Complexity metrics exceed thresholds
  • Red flags: file > 500 lines with scattered functions and global state, multiple global statements, no clear module/class organization, configuration mixed with business logic

Do NOT invoke when

  • Code is performance-critical and profiling shows perf optimization is needed first
  • Code is scheduled for deletion or replacement
  • External dependencies require upstream contributions instead
  • User explicitly requested perf optimization over readability

Core principles (priority order)

  1. Prefer structured OOP for complex code -- shared state, multiple concerns, scattered globals = restructure into classes/modules. (But: simple modules with pure functions, click/argparse CLIs, and functional pipelines DON'T need to be forced into classes.)
  2. Clarity over cleverness -- explicit beats implicit
  3. Preserve correctness -- all tests pass, behavior identical
  4. Single Responsibility -- one thing per class/function (SOLID)
  5. Self-documenting structure -- code = what, comments = why
  6. Progressive disclosure -- reveal complexity in layers
  7. Reasonable performance -- never sacrifice >2× without explicit approval

Hard constraints

  • SAFETY BY DESIGN -- mandatory migration checklists for destructive changes. CREATE → SEARCH → MIGRATE → VERIFY → only then REMOVE. NEVER remove before 100% migration verified.
  • STATIC ANALYSIS FIRST -- flake8 --select=F821,E0602 (or ruff check --select=F821) BEFORE tests. Catches NameErrors immediately.
  • PRESERVE BEHAVIOR -- all existing tests pass after.
  • NO PERF REGRESSION -- never degrade > 2× without explicit approval.
  • NO API CHANGES -- public APIs unchanged unless explicitly requested + documented.
  • NO OVER-ENGINEERING -- simple stays simple.
  • NO MAGIC -- no framework magic, no metaprogramming unless absolutely necessary.
  • VALIDATE CONTINUOUSLY -- static analysis + tests after each logical change.

Regression prevention (MANDATORY)

Refactoring must NEVER introduce regressions. Read references/REGRESSION_PREVENTION.md before any session.

Before each session:

  • Test suite passes 100%
  • Coverage ≥ 80% on target code (write tests FIRST if not)
  • Golden outputs captured for critical edge cases
  • Static analysis baseline saved

After EACH micro-change (not at the end -- every single one):

  • flake8 --select=F821,E999 → 0 errors
  • pytest -x → all passing
  • Spot check 1 edge case for unchanged behavior

If ANY check fails: STOP → REVERT → ANALYZE → FIX APPROACH → RETRY.

ANY REGRESSION = TOTAL FAILURE.

Workflow (4 phases)

Phase 1: Analysis

  1. Read the entire codebase section.
  2. Identify readability issues using references/anti-patterns.md (script-like/global-state, God Objects, nested conditionals, long functions, magic numbers, cryptic names).
  3. Assess architecture against references/oop_principles.md (proper classes/modules, encapsulated state, separated responsibilities, SOLID, DI vs hard-coded deps).
  4. Measure current metrics with scripts/measure_complexity.py or scripts/analyze_multi_metrics.py.
  5. Run linting analysis (see Tooling below).
  6. Check test coverage; identify gaps to fill BEFORE refactoring.
  7. Document with assets/templates/analysis_template.md.

Output: prioritized list of issues by impact and risk.

Phase 2: Planning

  1. Classify each change:

- Non-destructive (rename, docs, type hints) → low risk - Destructive (remove globals, delete functions, replace APIs) → high risk

  1. For DESTRUCTIVE changes -- migration plan is MANDATORY:

- Search ALL usages of each element to be removed - Document every usage (file, line, type) - No complete migration plan = cannot proceed with the destructive change

  1. Risk assessment per change (Low/Medium/High)
  2. Dependency map -- what depends on this code?
  3. Test strategy -- what tests are needed? what might break?
  4. Order changes safest → riskiest
  5. Document expected metric improvements

Output: refactoring plan, sequenced changes, migration plans, test strategy, rollback plan.

Phase 3: Execution

Non-destructive (safe anytime)
  1. Rename for clarity
  2. Extract magic numbers/strings to named constants
  3. Add/improve docs and type hints
  4. Add guard clauses to reduce nesting
Destructive (STRICT PROTOCOL)
  1. CREATE new structure (no removal) -- write new classes/functions + tests
  2. SEARCH for ALL usages of the element being removed
  3. CREATE migration checklist documenting every found usage
  4. MIGRATE one usage at a time, checking off the list, running static analysis + tests after each
  5. VERIFY complete migration -- re-run searches, should find zero old references
  6. REMOVE old code only after 100% migration verified
Execution rules
  • NEVER skip the migration checklist for destructive changes
  • Run static analysis BEFORE tests
  • One pattern at a time -- never mix multiple refactoring patterns in a single change
  • Atomic commits -- each migration step gets its own commit
  • Stop on ANY error (static analysis OR test failure) → immediate fix/revert
Recommended order
  1. Transform script-like code to proper architecture (references/examples/script_to_oop_transformation.md)
  2. Rename for clarity
  3. Extract magic numbers/strings to constants/enums
  4. Improve docs + type hints
  5. Extract methods to reduce function length
  6. Simplify conditionals with guard clauses
  7. Reduce nesting depth
  8. Final review: separation of concerns

Phase 4: Validation

  1. Static analysis FIRST: flake8 <file> --select=F821,E0602 # undefined names/variables -- MUST be 0 flake8 <file> --select=F401 # unused imports flake8 <file> # full quality check
  2. Full test suite → 100% pass required.
  3. Architecture validation: global state eliminated/encapsulated, proper modules/classes, separated responsibilities, SOLID compliance.
  4. Before/after metrics with scripts/measure_complexity.py or scripts/analyze_multi_metrics.py.
  5. Performance regression check with scripts/benchmark_changes.py for hot paths.
  6. Summary report using assets/templates/summary_template.md.
  7. Flag for human review if: perf degraded > 10%, public API signatures changed, test coverage decreased, significant architectural changes.

Refactoring patterns (catalog summary)

Full catalog with examples in references/patterns.md. Key patterns:

  • Guard Clauses -- early returns instead of nested conditionals
  • Extract Method -- split large functions into focused units (resets the nesting counter -- most powerful for cognitive complexity)
  • Dictionary Dispatch -- replace if-elif chains with lookup tables
  • Match Statement (Py 3.10+) -- counts as +1 total, not per branch
  • Named Boolean Conditions -- extract complex booleans into named variables
  • Encapsulate Global State -- move globals into classes with proper encapsulation
  • Group Related Functions -- organize scattered functions into classes by responsibility
  • Create Domain Models -- replace primitive dicts with dataclasses + enums
  • Apply Dependency Injection -- replace hard-coded deps with injected ones

For cognitive complexity calculation rules and reduction strategies, see references/cognitive_complexity_guide.md.

Naming conventions

  • Variables: descriptive, booleans as is_active / has_permission / can_edit, collections as plurals
  • Functions: verb + object (calculate_total, validate_email); boolean queries as is_valid() / has_items()
  • Constants: UPPERCASE_WITH_UNDERSCORES; replace magic numbers/strings
  • Classes: PascalCase nouns (UserAccount, PaymentProcessor)

Anti-patterns to fix (priority order)

Full catalog: references/anti-patterns.md.

  • Critical: script-like / procedural code with global state; God Object / God Class
  • High: complex nested conditionals (> 3 levels), long functions (> 30 lines), magic numbers, cryptic names, missing type hints, missing docstrings
  • Medium: duplicate code, primitive obsession, long parameter lists (> 5)
  • Low: inconsistent naming, redundant comments, unused imports

Tooling

Primary stack: Ruff + Complexipy (recommended for new projects)

uv tool install ruff complexipy radon wily

ruff check src/                                 # fast linting (Rust, replaces flake8+plugins)
complexipy src/ --max-complexity-allowed 15     # cognitive complexity (Rust)
radon mi src/ -s                                # maintainability index

Full configuration (pyproject.toml, pre-commit, GitHub Actions): references/cognitive_complexity_guide.md.

Alternative: flake8 + curated plugins

For projects already on flake8, see references/flake8_plugins_guide.md (curated 16-plugin selector list).

Multi-metric analysis

scripts/analyze_multi_metrics.py combines complexipy + radon + maintainability index in a single report.

MetricToolUse
Cognitive complexitycomplexipyHuman comprehension
Cyclomatic complexityruff (C901), radonTest planning
Maintainability indexradonOverall code health

Metric targets

  • Cyclomatic complexity: < 10 per function (warning 15, error 20)
  • Cognitive complexity: < 15 per function (SonarQube default; warning 20)
  • Function length: < 30 lines (warning 50)
  • Nesting depth: ≤ 3 levels
  • Docstring coverage: > 80% for public functions
  • Type-hint coverage: > 90% for public APIs

Historical tracking with Wily

Trends matter, not just thresholds. Setup + CI integration: references/cognitive_complexity_guide.md.

Common refactoring mistakes

Full guide: references/REGRESSION_PREVENTION.md. Key traps:

  1. Incomplete migration -- removing old code before ALL usages migrated (causes NameErrors).
  2. Partial pattern application -- applying refactoring to some functions but not others.
  3. Breaking public APIs -- changing signatures used by external code.
  4. Assuming tests cover everything -- tests pass but runtime errors occur (run static analysis!).

When to reach for which tool

  • clean-code (cross-language plugin) -- multi-language cosmetic cleanup; renames local vars, improves comments, simplifies structure. Lowest regression risk. Use for "make this readable", "clean up naming."
  • python-refactor (this skill) -- Python-only deep restructuring. OOP transformation, SOLID, complexity metrics, migration checklists, benchmark validation. Use for "refactor this module", "reduce complexity", "transform to OOP."

Escalation path: clean-code → python-refactor (safest to most thorough).

Integration

  • python-tdd -- set up tests before refactoring, validate coverage after
  • python-performance-optimization -- deep profiling before/after
  • python-packaging -- handle pyproject.toml + distribution if refactoring a library
  • uv-package-manager -- uv run ruff, uv run complexipy for tool execution
  • async-python-patterns -- reference async patterns when refactoring async code

When NOT to refactor

Perf-critical optimized code (profile first), code scheduled for deletion, external deps (contribute upstream), stable legacy code nobody needs to modify.

Limitations

Cannot improve algorithmic complexity (that's an algorithm change). Cannot add domain knowledge not in code/comments. Cannot guarantee correctness without tests. Style preferences vary -- adjust to team conventions.

Examples

references/examples/:

  • script_to_oop_transformation.md -- script → clean OOP architecture (flagship case study)
  • python_complexity_reduction.md -- nested conditionals and long functions
  • typescript_naming_improvements.md -- naming patterns (cross-language reference)

Success criteria

  1. Zero regressions -- all tests pass, behavior unchanged
  2. Golden master match for documented critical cases
  3. Complexity metrics improved (documented in summary)
  4. No perf regression > 10% (or explicit approval)
  5. Documentation coverage improved
  6. Code easier for humans to understand
  7. No new security vulnerabilities
  8. Atomic, well-documented git history
  9. Wily trend -- complexity not increased vs previous commit
  10. Static analysis shows improvement

平台分布

Codex

38.84%
按下载量换算461

Claude

31.87%
按下载量换算379

Cursor

17.5%
按下载量换算208

Gemini CLI

9.06%
按下载量换算108

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills