aos-refactor
Skill1 starsChanged 7 months agoMITView on GitHub
Guides safe code refactoring — identifies what to improve, ensures a test safety net exists first, and applies named refactoring patterns (extract function, rename, decompose conditional, strangle fig, parallel change). Reports REFACTOR/WARN with the pattern name and step-by-step instructions. Use when user wants to refactor, reduce complexity, clean up code, or says "improve this without changing behaviour".
In this repository18 other files it gives its agents.
- AGENTS.mdAGENTS.md
- aos-auditSkill
- aos-ciSkill
- aos-codereviewSkill
- aos-debuggingSkill
- aos-featureSkill
- aos-frontendSkill
- aos-generateSkill
- aos-hardeningSkill
- aos-implementing-featuresSkill
- aos-pragmaticSkill
- aos-qaSkill
- aos-reviewSkill
- aos-scaffoldSkill
- aos-setupSkill
- aos-tddSkill
- aos-uxSkill
- aos-vuetifySkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Never refactor without a safety net: If the code has no tests, write characterisation tests first — then refactor.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
/aos-refactor
Select files to refactor, then run /aos-refactor.
For targeted refactors: /aos-refactor complexity · /aos-refactor naming · /aos-refactor duplication · /aos-refactor debt · /aos-refactor size
Golden rule
Never refactor without a safety net. If the code has no tests, write characterisation tests first — then refactor. A characterisation test is a test that pins the current behaviour, not the desired behaviour.
What gets checked
Safety net
- The behaviour being changed has tests that describe outcomes, not implementation details
- CI runs automatically so regressions are caught immediately
- Tests do not assert internal state or method calls — they will survive a refactor
Naming
- Variable names reveal intent:
usernotu,expiresAtnotts - Functions named for what they return or do:
getUserByEmail, notprocess - Booleans positive and assertive:
isActive,hasPermission— notnotInactive,permMissing - No unexplained abbreviations (HTTP, URL, ID, OK are fine;
usr,mgr,tmpare not) - No misleading names —
getUserthat also deletes is a broken contract
Function complexity
- Functions have a single responsibility
- Cyclomatic complexity ≤ 10 per function (count
if,else,for,while,case,&&,||) - Functions ≤ 30 lines — if scrolling is required to understand it, extract
- Nested
if/elsedeeper than 3 levels flattened with guard clauses or extraction - No functions that take a boolean flag to switch between two different behaviours — split into two
Duplication
- Duplicate logic extracted to a shared, named function
- Duplicate configuration extracted to a named constant
- Similar classes with minor differences unified with a parameter or strategy pattern
Abstraction level
- No premature abstraction — extracted only when used in ≥ 2 real places
- Abstractions named for what they do, not how:
PaymentGateway, notIStripeWrapper - No leaky abstractions — the caller does not need to know the implementation detail
- Code at one level of abstraction per function — no mixing of high-level intent and low-level detail
Technical debt classification
- Reckless / inadvertent — never acceptable. Fix now.
- Prudent / intentional — documented in a tracked issue with a timeline.
- Bit rot — outdated patterns. Fix opportunistically using the Boy Scout Rule.
Refactoring patterns
| Pattern | When to apply |
| Extract function | A block of code does one thing and can be given a name |
| Rename | The current name is misleading, abbreviated, or inaccurate |
| Move | Code lives in the wrong layer or module |
| Inline | An abstraction is used once and adds no clarity |
| Decompose conditional | A complex if condition is hard to read — extract into a named predicate |
| Replace magic number | A literal value appears without explanation |
| Introduce parameter object | A function takes 4+ related arguments |
| Guard clauses | Nested conditionals — flatten with early returns |
| Split function | A function takes a boolean flag to choose between two paths — split it |
| Strangle fig | Replacing a large system incrementally alongside the old one |
| Parallel change | Changing a public function signature without a big-bang migration |
Output format
[WARN] Safety net — OrderService has no tests
Action: write characterisation tests before refactoring
Suggested: it('should return the correct total for a standard order')
Suggested: it('should apply promo code discount when code is valid')
[REFACTOR] Extract function — discount logic on lines 45–68 buried inside processOrder()
File: src/orders/order.service.ts:45
Pattern: Extract Function
Steps:
1. Create: async applyPromoCode(subtotal: number, code: string): Promise<number>
2. Move lines 45–68 into the new function
3. Replace with: const finalPrice = await this.applyPromoCode(total, code)
4. Run tests — no behaviour change should occur
[REFACTOR] Split function — processUser(user, isDryRun: boolean) does two different things
File: src/users/user.service.ts:88
Pattern: Split Function
Steps:
1. Create validateUser(user) — the dry-run path
2. Create persistUser(user) — the real path
3. Call the right one at each call site
4. Delete processUser
[REFACTOR] Naming — variable 'd' holds a discount percentage
File: src/orders/order.service.ts:47
Pattern: Rename
Fix: rename d → discountPercentFull reference
See REFERENCE.md for before/after examples of every pattern.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

