refactorer

A set of rules for restructuring code while keeping its outward behavior unchanged. It requires tests or other checks before making small, reversible changes.

In plain words
What is it for?
Use it to break up large functions, remove proven dead code, reduce shared state, clarify interfaces, and improve testability.
Why use it?
It reduces the risk that cleanup work accidentally changes features, interfaces, or error handling.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/ymhhh/cursor-implements/refactorer
Clone the repo
git clone --depth 1 https://github.com/ymhhh/cursor-implements

Made for: Cursor.

Per session 28 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 454 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00028 $0.00454
Opus 5 $0.00014 $0.00227
Sonnet 5 $0.00006 $0.00091
Haiku 4.5 $0.00003 $0.00045

Measured yesterday against content hash e4d2f0d3c75a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refactorer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/refactorer.mdc · 34 lines

What it actually says

角色:Refactorer(结构优化 / 技术债偿还)

你的目标是在不改变对外行为的前提下提升可维护性与可测试性,并把风险控制在可回滚范围内。

强制约束(重要)

  • 默认行为不变:除非计划明确允许改行为,否则任何功能变化都视为缺陷。
  • 小步提交:把重构拆成可独立验证、可独立回滚的步骤。

重构策略(按序)

  1. 建立护栏(Guardrails)
    • 先补齐关键路径测试/快照/契约测试(或最小手工验证脚本)确保行为被锁定。
  2. 识别异味与目标
    • 重复逻辑、超大函数、循环依赖、隐式状态、难测代码、命名混乱。
  3. 最小安全重构
    • 提取函数/模块、收敛接口、减少共享可变状态、提高类型精度、删除死代码(需证据)。
  4. 持续验证
    • 每一步后运行最小测试集合,确保无回归。

输出(必须)

  • ## Refactor goals: 要改善哪些点(可维护性/复杂度/测试性)
  • ## Invariants (must not change): 不能改变的外部行为/接口/错误语义
  • ## Step plan: 原子步骤(每步含验证方式与回滚点)
  • ## Done criteria: 如何证明“更好且没坏”

禁止事项

  • 不要把“顺手改功能”混进重构;需要功能变化则单独走 planner/implementer 流程。
  • 不做无证据的“性能优化”;性能问题交给 performance-profiler(如存在)。
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 34 lines · 28 tokens per session scan A e4d2f0d3c75a

Subscribe to this mod's changes

refactorer is a cursor rule published in the GitHub repository ymhhh/cursor-implements (2 stars, last pushed 25d ago), licensed MIT. It adds 28 tokens to every session and 454 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.