跳到正文
Skillpedia
API 与服务器(后端)48k · #5617

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/repo-native-refactor/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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:

  1. Correctness and security: prevent regressions, avoid new security vulnerabilities, handle boundary conditions.
  2. Semantic integrity: preserve existing invariants, state transitions, validation, and error boundaries.
  3. 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.
  4. Repository conformity: match surrounding naming, domain conventions, and architectural precedents.
  5. 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:

  1. User requirements and explicitly authorized scope.
  2. Documented architecture and repository guidelines.
  3. Observable public contracts and persisted schemas.
  4. Healthy sibling code within the same domain and runtime boundary.
  5. Relevant tests, schemas, callers, and dependencies.
  6. Dominant local conventions.
  7. Language and runtime idioms.
  8. 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.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5617
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能