repo-native-refactor
它能做什么
这个工具可以帮你安全地审查和整理编程代码。它会检查错误,确保代码能像预期一样继续运行,并在不改变核心行为的前提下做一些小的改进。
适用场景
- ✓当你希望 AI 审查代码,但不想让它改动代码时。
- ✓当你想对已经能正常运行的代码做一些小修复时。
- ✓当你想整理或简化代码中重复的部分时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/repo-native-refactor/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请审查这段代码,确保它不会破坏重要功能,并看看有没有简单的地方可以改进。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会把代码和安全、功能、代码组织方面的规则逐一对照来分析。它会优先修复错误,并保持已经正常工作的部分不变,只做必要且安全的修改。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Repo-native refactor
When to Use
- Use when the user asks to review a diff, branch, or PR for correctness, contract breaks, or operational risk.
- Use when the user authorizes bounded cleanup before opening a PR or asks to consolidate duplicated policy with shared ownership.
- Use for repository rehabilitation only when the user explicitly requests work across multiple domains.
- Establish review-only, edit, or combined authority before choosing the operating mode.
Produce the smallest coherent change that belongs naturally in the target repository.
Prioritize in order:
- Correctness and security: prevent regressions, avoid new security vulnerabilities, handle boundary conditions.
- Semantic integrity: preserve existing invariants, state transitions, validation, and error boundaries.
- Contracts stay as declared: the rule lives in
references/shared-contracts.md§1. Preserve the authorized target contract; otherwise keep exact declared types. Internal helpers are fine when exposed contracts stay exact. - Repository conformity: match surrounding naming, domain conventions, and architectural precedents.
- Economy and simplicity: minimal intervention. Delete dead weight, avoid premature abstractions.
This is a post-implementation audit and small cleanup skill. It is not permission to redesign the repository. Establish a concrete consequence such as inconsistent behavior, duplicated policy that must change together, unclear ownership, avoidable resource cost, or a demonstrated maintenance obstacle. Leave healthy code unchanged when the benefit is speculative.
Minimal intervention and evidence gate
- Evidence-based intervention: refactor only with concrete evidence of divergence, defect, or operational risk. If greenfield code or an additive diff is already minimal, idiomatic, and passing, leave it. A pattern you recognize is a candidate finding, not a reason to change anything.
- Semantic DRY (Cost-benefit consolidation): merge duplicated logic only when the copies share an owner, an invariant, and a reason to change, and only if merging saves more than it costs. Leave similar-looking checks in separate domains alone, and keep small local duplication when merging would obscure ownership.
- Contract boundary protection: preserve public interfaces, parameter names, and return types, except where the task clearly authorizes the change. During cleanup, keep the authorized target contract; don't revert to the old one.
Operating modes
- Review vs. Refactor Authority: first establish the outcome: findings, edits, or both. Review-only means inspection and verification, no source edits. Authorized cleanup allows bounded corrections; don't ask approval again for routine choices.
- Change-set cleanup: for a working tree, branch, commit range, feature, or bounded checkpoint. Work diff-first; read surrounding code only to understand ownership, contracts, and precedent.
- Repository rehabilitation: only when explicitly requested across multiple domains. Read repository rehabilitation, build a short profile, and work in batches you can verify independently.
Evidence hierarchy
Use the evidence hierarchy to guide investigation, not to resolve material contradictions automatically. Reconcile conflicting requirements, documentation, callers, and tests before changing the affected contract. When repository patterns conflict, resolve in order:
- User requirements and explicitly authorized scope.
- Documented architecture and repository guidelines.
- Observable public contracts and persisted schemas.
- Healthy sibling code within the same domain and runtime boundary.
- Relevant tests, schemas, callers, and dependencies.
- Dominant local conventions.
- Language and runtime idioms.
- Conservative, idiomatic defaults.
Never treat a temporary workaround, buggy sibling, or accidental pattern as precedent.
Workflow
1. Establish scope and baseline
Before mutating code, identify:
- Comparison base and working-tree state.
- In-scope files vs. untouched user modifications.
- Existing verification commands and their current pass/fail status.
Differentiate pre-existing failures from regressions introduced by this pass. Never claim a check ran when it did not.
2. Establish intent, ownership, and preservation
Refactoring is behavior-preserving by default. Protect:
…
常见问题
AI 能把代码完全改写吗?
不能,重点是审查和小范围的整理。大幅改动或重新设计不是它的主要目标。
“preserving authorized contracts”是什么意思?
这指的是代码的规则,以及它与其他部分的通信方式(即它的“公共接口”)应保持不变,除非获得明确授权才能修改。
AI 会删除没有使用的代码吗?
如果删除是安全且合理的,这个工具可以移除不必要的代码,让代码更简洁。
详情
作者的原始描述
Review diffs without editing, or perform evidence-based cleanup while preserving authorized behavior, public contracts, and domain ownership.
热度
- GitHub 星标
- 48k
- 排名
- #5617
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。