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.
npx skills add hxy91819/mason-skills --skill safe-refactorgit clone --depth 1 https://github.com/hxy91819/mason-skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/hxy91819/mason-skills/safe-refactor)<a href="https://agentmods.dev/skills/hxy91819/mason-skills/safe-refactor"><img src="https://agentmods.dev/badge/skills/hxy91819/mason-skills/safe-refactor/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/hxy91819/mason-skills/safe-refactor"><img src="https://agentmods.dev/badge/skills/hxy91819/mason-skills/safe-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00031 | $0.02352 |
| Opus 5.5 | $0.00012 | $0.00941 |
| Sonnet 5.5 | $0.00006 | $0.00470 |
| Haiku 4.5 | $0.00003 | $0.00235 |
Grade A, and why
safe-refactor 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 29d ago.
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.
How it starts
The opening of the file, as written. The whole thing — 126 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Safe Refactor:先圈边界,再改代码
这是流程类 Skill,仅在用户显式调用 $safe-refactor 时运行。完整流程把重构推进到“具备进入发布流程的证据”;只做 review 时停在审查结论。不负责宣布生产安全,也不自动推送、合并、部署。
适合共享组件、数据访问(如 N+1)、异步化、跨语言替换,或审查/接手一份没有事前验证的重构 diff。小范围纯函数整理只需按下文“小任务”走轻量路径。
入口与模式
接受自然语言目标;不要求用户填写整份表。先读仓库说明、当前分支、已有任务单、测试与发布约定,能查到的信息不反复询问。
| 请求 | 模式 | 读取 |
|---|---|---|
| 新的重构目标 | 完整流程(下文 1–7) | 全部阶段按到达时读取 |
| “只分析影响面” | plan 或 actual 影响分析,不改生产代码 | change-impact.md |
| “只补基线/测试” | 行为基线 | behavior-baseline.md |
| “重构已完成,只做 review” | 事后审查实际 diff 和现有证据,不继续实现 | verify.md 的事后 review 分支 |
| 协调者派来的独立验收,或明确要求正式证据门禁 | verify,不改生产代码 | verify.md 的正式验收分支 |
| 已有 diff,要求继续重构或补齐事前基线 | 下文“接手并继续已有改动” | — |
| 继续任务 | 读取工作单及当前 Git 状态,先检查版本和证据是否仍匹配 | — |
所有模式先读 共享规则。完整流程和接手实施用 工作单 持久化状态;仅做事后 review 可直接使用现有材料。运行脚本时读 工具说明。
用户只要求 review 时,优先按其指定的旧版和候选版划界;未指定则从当前分支、Git 历史及未提交改动确定实际范围,并说明候选是固定提交还是工作区状态。只报告发现的问题、验证结果和证据缺口,不补写“事前”批准或进入下文实施步骤。
手动调用示例:$safe-refactor 只做 review:审查当前分支相对 main 的已完成重构,包含未提交改动;检查行为变化、调用方和现有测试,不修改代码。
1. 收敛任务
记录一句话目标、可观察的收益标准、不做什么、原始版本 origin_revision、当前候选版本、环境限制和授权边界。不要把重构顺便升级为改需求、修全部历史 bug 或重写技术栈。
性能优化先确认瓶颈证据;结构重构也要有可验收收益,例如依赖方向、重复规则数量、模块公开面,而不只是“代码更漂亮”。没有足够收益时推荐不改或缩减目标。
默认最多两轮局部修复、一轮重新规划;这是可调整默认值,不是最佳次数的事实判断。沿用用户或项目已有预算;不得自行续费式增加预算。耗尽则保留工作并报告下一项决策。
2. 影响面分析(plan)
按 change-impact.md 的 plan 模式,基于目标、原始版本、现有改动和约束给出最小可验证方案。
必须得到:改动的语义、受影响业务入口与资源、必要契约、未知项、推荐策略、允许/保护路径、最小验证集。不要把路径清单当语义影响的完整证明。
将方案写入 policy.json 和工作单。范围由用户明确授权或项目已有可信策略批准;低风险、已授权范围内可自动继续,不必每个文件都问一次。共享语义扩大、删除数据、改变权限、改变需求、放宽验收或超预算,需要明确的新决策。
3. 行为基线
按 behavior-baseline.md 在旧生产实现上建立测试,不先改实现再反推答案。
测试准备可能需要一个仅增加测试/夹具的提交:
origin_revision:开始任务时的旧代码。base_revision:测试基线准备完成后的固定提交,生产行为仍是旧的。- 对这两版的差异单独审查;基线准备若必须改变生产代码,拆成有证据的小步骤,不偷偷夹带。
记录契约、断言依据、基线执行、针对关键规则的红控结果。性能目标的旧版测量与业务回归分开。
基线就绪后,冻结 policy.json 的批准摘要及 seal.json;冻结的是受保护的断言/夹具/规范边界,不是整个测试仓库。没有实际执行能力时标记 INSUFFICIENT,不能宣称基线已建立。
What ships with it
36 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
- agents/openai.yaml 308 B
- assets/baseline.md 959 B
- assets/contract-verdict.template.json 352 B
- assets/contract.template.json 244 B
- assets/impact.md 1.1 KB
- assets/policy.template.json 822 B
- assets/release-handoff.md 893 B
- assets/verification.md 873 B
- assets/verification.template.json 981 B
- assets/work-item.md 1.3 KB
- examples/n-plus-one/candidate/api.py 170 B runs code
- examples/n-plus-one/candidate/batch.py 432 B runs code
- examples/n-plus-one/fixture/.gitignore 19 B
- examples/n-plus-one/fixture/benchmark.py 808 B runs code
- examples/n-plus-one/fixture/src/__init__.py 0 B runs code
- examples/n-plus-one/fixture/src/api.py 252 B runs code
- examples/n-plus-one/fixture/src/other_api.py 177 B runs code
- examples/n-plus-one/fixture/src/shared.py 269 B runs code
- examples/n-plus-one/fixture/src/store.py 1.1 KB runs code
- examples/n-plus-one/fixture/tests/__init__.py 0 B runs code
- examples/n-plus-one/fixture/tests/test_contract.py 1.9 KB runs code
- examples/n-plus-one/README.md 2.4 KB
- examples/n-plus-one/run_demo.py 8.9 KB runs code
- references/behavior-baseline.md 5.1 KB
- references/change-impact.md 4.7 KB
- references/checklists.md 3.8 KB
- references/ci-integration.md 3.8 KB
- references/evidence.md 3.9 KB
- references/tooling.md 8.8 KB
- references/verify.md 5.8 KB
- references/workflow.md 5.6 KB
- scripts/refactor_guard.py 34 KB runs code
- scripts/unittest_junit.py 4.2 KB runs code
- tests/agent-evals.jsonl 2.6 KB
- tests/test_guard.py 19 KB runs code
- tests/test_package.py 4.3 KB runs code
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.
- 29d ago First seen · 126 lines · 31 tokens per session scan A 88b6ca6d4e63
safe-refactor is a skill published in the GitHub repository hxy91819/mason-skills (3 stars, last pushed yesterday), licensed MIT. It adds 31 tokens to every session and 2,352 once invoked, about $0.0001 per session on Opus 5.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-09-27.
Other skills, from other repositories
adk-go-self-review
Review an ADK Go change the way a maintainer will — a fresh-context pass over the whole diff, five lenses (correctness and tests, scope, simplicity, style, adk-python parity), and the mutation check that proves your tests pin the change. Use before opening a PR, before any later push that changes code, and when asked…
adversarial-reviewer
Stress-test a code change for concrete correctness defects, unsafe assumptions, and failure modes. Use when the user explicitly asks for an adversarial review, a deep bug hunt, or to tear a change apart, or to check your own change before submitting it. Do not use for ordinary review, style feedback, or general…
go-testing
Trigger: Go tests, go test coverage, Bubbletea teatest, golden files. Apply focused Go testing patterns.
semgrep-rule-variant-creator
Creates language variants of existing Semgrep rules. Use when porting a Semgrep rule to specified target languages. Takes an existing rule and target languages as input, produces independent rule+test directories for each language.
brooks-sweep
Full-sweep mode: runs a unified analysis across all quality dimensions — code decay, architecture, tech debt, and test quality — then applies fixes directly to the codebase. Safe changes are auto-applied; risky changes are confirmed before execution. Drawing on twelve classic engineering books. Triggers when: user…
plugin-review
Review plugin quality with tiered checks and dependency scoping. Use for PR and pre-release audits.