code-refactor
Refactor Python code to match this repo's coding standards and style. Use when the user asks to "refactor", "clean up", "fix coding standards", or "apply best practices" to a module, file, or directory in this repo. Applies python-best-practices, pydantic v2, pytorch-lightning, and python-docs conventions as relevant to the target code.
- License 许可
- MIT
- 最近更新
- 2026-09-17
- Stars
- ★ 5
- Forks
- 0
01 前言 Front Matter
- name
- code-refactor
- description
- Refactor Python code to match this repo's coding standards and style. Use when the user asks to "refactor", "clean up", "fix coding standards", or "apply best practices" to a module, file, or directory in this repo. Applies python-best-practices, pydantic v2, pytorch-lightning, and python-docs conventions as relevant to the target code.
02 资源文件 4
- 参考文档references/checklist.md3.6 KB
- 参考文档references/docs-patterns.md2.5 KB
- 参考文档references/pydantic-patterns.md3.1 KB
- 参考文档references/pytorch-patterns.md2.5 KB
03 SKILL.md 正文
Code Refactor Skill
Systematically refactor Python code to match this repo's standards.
Workflow
1. Read Target Code
Read every file in the target module. Never propose changes to code you haven't read.
2. Audit Against Checklist
Run through references/checklist.md and note every violation. Group them by category so the user can see the full picture before any edits are made.
3. Run Static Analysis
uv run ruff check <target>
uv run mypy <target>
Report all errors as part of the audit — these are additional violations on top of the checklist.
4. Apply Fixes
Apply all fixes. Prefer the Edit tool over Write for existing files (smaller diffs, easier review). Make all independent edits in parallel.
Priority order (highest impact first):
- Type safety — enums over bare strings,
from __future__ import annotations, proper return types - Pydantic — snake_case fields with aliases,
model_config, field validators (seereferences/pydantic-patterns.md) - Error handling — replace
assertwithif/raise, add context to re-raised exceptions - Python best practices — frozen dataclasses, Protocol types, avoid mutable defaults
- PyTorch/Lightning — only apply if the module contains
torchornn.Modulecode (seereferences/pytorch-patterns.md) - Docs — public functions must have docstrings (see
references/docs-patterns.md)
5. Verify
uv run ruff check <target>
uv run ruff format <target>
uv run mypy <target>
uv run pytest tests/unit/<target-name>/ -v
All checks must pass before declaring done. If tests fail, fix them — don't skip.
6. Summarise
Report a table of every change made, grouped by category. Include file and line references.
Repo-Specific Conventions
- Python: 3.12 — use
StrEnum,match,X | Yunions,from __future__ import annotationsin every file - Linter/Formatter: Ruff (88 char line length)
- Type checker: mypy (strict — all errors must be resolved)
- Package manager: uv (
uv run <cmd>) - Tests: pytest, mirror source structure under
tests/unit/ - Logging:
from logging_utils import get_loggerthenlogger = get_logger(__name__)— neverlogging.getLogger(__name__)orprint() - Imports: stdlib → third-party → local, each group separated by blank line
- Config: TOML or YAML only — never JSON for config files
When to Apply Each Sub-Skill
| Code contains | Apply |
|---|---|
BaseModel, Pydantic fields |
references/pydantic-patterns.md |
torch, nn.Module, LightningModule |
references/pytorch-patterns.md |
| Public classes / functions without docstrings | references/docs-patterns.md |
| All Python files | references/checklist.md |
04 同仓库更多 Skills
git-operations
暂无简介
python-best-practices
暂无简介
typst-paper
Typst academic paper assistant for existing `.typ` paper projects in English or Chinese. Use this skill whenever the user wants to compile, audit, or improve a Typst paper, including format checks, bibliography validation for BibTeX or Hayagriva, grammar/sentence/logic review, expression polishing, translation, title optimization, pseudocode review, algorithm block cleanup, de-AI editing, or experiment-section review. Trigger even when the user only mentions one Typst file, one bibliography issue, one pseudocode block, or one section rewrite. Also trigger when the user mentions ".typ files", "typst compile error", "typst export", "typst bibliography", `algorithm-figure`, `lovelace`, or `algorithmic` even without saying the word "Typst" explicitly.
typeset
Improves typography by fixing font choices, hierarchy, sizing, weight, and readability so text feels intentional. Use when the user mentions fonts, type, readability, text hierarchy, sizing looks off, or wants more polished, intentional typography.
teach-impeccable
One-time setup that gathers design context for your project and saves it to your AI config file. Run once to establish persistent design guidelines.
research-paper-writing
Improve academic paper writing quality for ML/CV/NLP-style papers with clear section structure, paragraph flow, and reviewer-facing presentation. Use when drafting or revising Abstract, Introduction, Related Work, Method, Experiments, or Conclusion; polishing figures/tables; checking claim-support alignment; or performing self-review before submission.