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 agentmods add skills/asgarovf/locusai/refactoringnpx skills add asgarovf/locusai --skill refactoringgit clone --depth 1 https://github.com/asgarovf/locusaiWrote 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/asgarovf/locusai/refactoring)<a href="https://agentmods.dev/skills/asgarovf/locusai/refactoring"><img src="https://agentmods.dev/badge/skills/asgarovf/locusai/refactoring.svg" alt="Measured on agentmods" 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.01441 |
| Opus 5 | $0.00015 | $0.00720 |
| Sonnet 5 | $0.00006 | $0.00288 |
| Haiku 4.5 | $0.00003 | $0.00144 |
Grade A, and why
refactoring 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 6d 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 — 215 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Refactoring
When to use this skill
- Code is hard to read or understand
- Duplicated logic across multiple places
- Functions or classes are too large
- Adding a feature requires touching too many files
- Code smells identified during review
- Preparing code for a new feature
Golden rule
Refactoring must not change behavior. Tests should pass before and after. If no tests exist, write them first.
# Run tests before starting
npm test # or pytest, go test, etc.
# Make refactoring changes
# Run tests after every change
npm test
Common refactoring patterns
Extract function
When a block of code does one distinct thing:
// Before
function processOrder(order: Order) {
// validate
if (!order.items.length) throw new Error('Empty order');
if (order.items.some(i => i.quantity <= 0)) throw new Error('Invalid quantity');
if (!order.customerId) throw new Error('No customer');
// calculate total
let total = 0;
for (const item of order.items) {
total += item.price * item.quantity;
}
const tax = total * 0.1;
const finalTotal = total + tax;
// save
db.save({ ...order, total: finalTotal });
}
// After
function validateOrder(order: Order): void {
if (!order.items.length) throw new Error('Empty order');
if (order.items.some(i => i.quantity <= 0)) throw new Error('Invalid quantity');
if (!order.customerId) throw new Error('No customer');
}
function calculateTotal(items: OrderItem[]): number {
const subtotal = items.reduce((sum, i) => sum + i.price * i.quantity, 0);
return subtotal * 1.1; // includes 10% tax
}
function processOrder(order: Order) {
validateOrder(order);
const total = calculateTotal(order.items);
db.save({ ...order, total });
}
Replace conditional with polymorphism
// Before: switch on type
function calculateShipping(order: Order): number {
switch (order.shippingType) {
case 'standard': return order.weight * 1.5;
case 'express': return order.weight * 3.0 + 10;
case 'overnight': return order.weight * 5.0 + 25;
default: throw new Error('Unknown shipping type');
}
}
// After: strategy pattern
const shippingStrategies: Record<string, (weight: number) => number> = {
standard: (weight) => weight * 1.5,
express: (weight) => weight * 3.0 + 10,
overnight: (weight) => weight * 5.0 + 25,
};
function calculateShipping(order: Order): number {
const strategy = shippingStrategies[order.shippingType];
if (!strategy) throw new Error('Unknown shipping type');
return strategy(order.weight);
}
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.
- 6d ago First seen · 215 lines · 31 tokens per session scan A d7b74ef53d3d
refactoring is a skill published in the GitHub repository asgarovf/locusai (23 stars, last pushed 5mo ago), licensed MIT. It adds 31 tokens to every session and 1,441 once invoked, about $0.0002 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-30.
Other skills, from other repositories
refactoring-patterns
Apply safe refactoring patterns to improve code structure without changing behavior. Use when cleaning up code, reducing technical debt, or improving maintainability.
refactoring-workflow
Improve the structure of existing code without changing its behaviour, in small verified steps under a green test suite. Use when the user asks to refactor, clean up, restructure or simplify code, wants to reduce duplication or coupling, is preparing a codebase for a feature it cannot currently accommodate, or when…
code-quality-review
Run a maintainability and structure review focused on abstraction quality, branching complexity, file growth, canonical ownership, duplication, and refactoring opportunities. Use when the user asks for code quality review, maintainability review, 代码质量审查, 可维护性审查, or comments about whether the change stays easy to…
code-refactor
Implement safe, behavior-preserving code refactors after inspecting the existing project. Use when the user asks to refactor, split large files, extract methods, reduce duplication, rename, clean dead code, or says 重构代码, 拆分模块, 提取方法, 优化命名, 优化注释, 删除未调用代码. For broad requests, plan safe slices and wait for approval; for…
arch-optimize
架构优化技能 v3.2:六大衰退风险扫描(R1-R6)、质量度量(MI/CC/健康分)、回归防护。五阶段工作流配 4 个零依赖本地脚本(archscan/depgraph/riskdiagnose/qualitymetrics/regressionguard),全部输出 JSON。在架构审查、技术债评估、代码重构、质量提升、工程结构评审时调用。.
refactoring-expert
Expert skill for Clean Code, Refactoring, and Design Patterns. Combines Refactoring Guru's deep patterns with Supercent's rigorous operational metrics and validation workflows.