ProSkillsLibraryFreePassScan
Code Review

Code Review · agent skill

Refactor Surgeon

Behaviour-preserving refactors in small steps.

What it does

Loads when it is needed

Your agent loads it when the user wants code restructured without changing what it does. It carries 5 rules and reads a profile.md with your details before it starts, so the output matches your brand and project.

Same prompt, with and without

Make shipping cost testable

Prompt · Refactor placeOrder so the shipping cost can be tested on its own. Behaviour must not change.

src/orders/place.ts
 1 export function placeOrder(cart: Cart, user: User, db: Db) {
 2   let weight = 0;
 3   for (const i of cart.items) weight += i.grams * i.qty;
 4   let shipping;
 5   if (user.country === "US") shipping = weight > 2000 ? 12.5 : 7;
 6   else if (user.country === "CA") shipping = weight > 2000 ? 18 : 11;
 7   else shipping = 25;
 8   if (cart.subtotal > 100 && user.country === "US") shipping = 0;
 9   const total = cart.subtotal + shipping;
10   db.orders.insert({ userId: user.id, total, shipping });
11   return total;
12 }
Callers (from grep): checkout route and 2 scripts. Existing tests for this file: none.

Profile used: Project: online shop checkout; Stack: TypeScript, vitest, tsc; Strictness: Standard; Conventions: conventional commits, tests beside source

Without the skill
Extract the shipping logic into a pure function, keep the calculation identical, and call it from placeOrder. ```ts export function calculateShipping( items: { grams: number; qty: number }[], country: string, subtotal: number, ): number { let weight = 0; for (const i of items) weight += i.grams * i.qty; let shipping: number; if (country === "US") shipping = weight > 2000 ? 12.5 : 7; else if (country === "CA") shipping = weight > 2000 ? 18 : 11; else shipping = 25; if (subtotal > 100 && country === "US") shipping = 0; return shipping; } export function placeOrder(cart: Cart, user: User, db: Db) { const shipping = calculateShipping(cart.items, user.country, cart.subtotal); const total = cart.subtotal + shipping; db.orders.insert({ userId: user.id, total, shipping }); return total; } ``` placeOrder's signature is unchanged, so the checkout route and the 2 scripts need no edits. Since there are no tests, add `place.test.ts` beside it for calculateShipping: US under/over 2000g, exactly 2000g (not >), CA both tiers, other country, US subtotal 100 (not free) and 101 (free), CA over 100 (still charged). Run tsc and vitest. Commit: `refactor: extract calculateShipping from placeOrder`.
With the skill
Goal: make shipping cost testable alone, behaviour unchanged. Scope: src/orders/place.ts. Before any edit: run the suite, `tsc` and the linter, and stop if red (not run here, snippet only). Commit 1, test only: pin today's behaviour, odd parts included. - US, 500g, subtotal 50: shipping 7, total 57 - US, 2500g, 50: 12.5, total 62.5; exactly 2000g: 7 (strict >) - US, subtotal 100: 7, total 107 (strict >); 100.01: 0, total 100.01 - CA, 100g, 150: 11, total 161 (free shipping is US only) - DE: 25; empty US cart: 7 Each case also asserts the inserted row {userId, total, shipping}. Plan, one named move per commit, tests green after each: 2. refactor: extract function weightOf from placeOrder 3. refactor: extract function shippingFor(subtotal, weight, country); the free-shipping override stays inside, branch order unchanged 4. refactor: replace country conditional with a rate table {US: [7, 12.5], CA: [11, 18]}, default 25 After step 4, shippingFor is pure with its own tests, placeOrder reads in about five lines, and the pinned tests never changed. Found, not fixed: free shipping only for US (intentional? ask); float arithmetic on money (place.ts:9); the insert sits inside the total calculation, a Separate Query from Modifier candidate.

Both answers from the same model (Claude sonnet), 2026-10-16. The one without the skill was written in a separate session that never saw it. Shortened where marked with …

Install

One command, in your project

It detects your agent; add --agent all for every agent.

npx proskills-cli add refactor-surgeon --order <order id from your receipt>

Or copy the skill folder (the one holding SKILL.md) into the directory your agent reads, then restart it or start a new session.

AgentThis projectEvery project
Claude Code.claude/skills/~/.claude/skills/
Cursor.agents/skills/ (or .cursor/skills/)~/.cursor/skills/
Codex.agents/skills/~/.agents/skills/
Gemini CLI.agents/skills/ (or .gemini/skills/)~/.gemini/skills/

Changelog

What changed

  • v1.0.0 · 2026-10-16
    • First versioned release: Behaviour-preserving refactors in small steps.
    • Scanned 100/100 before release.

Keep it current with npx proskills-cli update; your profile.md is never touched. Everyone who bought it gets the update free and an email when it lands.

Same collection

More from Code Review

The scan checks spec compliance, token cost, clarity and security patterns. A clean scan is not a guarantee: static scanners can be evaded. Scan any skill yourself.