skills/code-refiner/SKILL.md
Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust. Targets complexity, anti-patterns, readability debt. Triggers on: "simplify this code", "refactor for clarity", "reduce complexity", "make this more readable", "tech debt cleanup", "too much nesting".
npx skillsauth add mathews-tom/armory code-refinerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A structured, multi-pass code refinement skill that transforms complex, verbose, or tangled code into clean, idiomatic, maintainable implementations — without changing what the code does.
The goal is not fewer lines. The goal is code that a tired engineer at 2am can read, understand, and safely modify. Every change must pass three tests:
When clarity and brevity conflict, clarity wins. When idiom and explicitness conflict, consider the team's experience level. When DRY and locality conflict, prefer locality for code read more than modified.
git diff) when the user doesn't specify target filesscripts/complexity_report.py for quantitative complexity metricsFollow this sequence. Each phase builds on the previous one. Do not skip phases, but adapt depth to the scope of the request (a single function gets a lighter pass than a full module).
Before touching anything, build a mental model:
git diff --name-only HEAD~5 or git diff --staged --name-onlyreferences/ if needed for idiom-specific guidanceIdentify what's actually wrong before reaching for solutions. Categorize issues by severity:
Critical (always fix):
High (fix unless there's a clear reason not to):
Medium (fix when it improves clarity without adding risk):
Low (fix only in a dedicated cleanup pass):
Apply changes using these tactics, ordered by impact-to-risk ratio:
Remove before restructuring. Less code = less to think about.
Reduce nesting and cognitive load:
if nesting to early returnsis_valid_order = ...)else branch is the "happy path", flip itMake the code's intent visible:
data → user_records, process → validate_and_enqueueApply language-specific patterns (consult references/<language>.md for details):
? operator, From/Into, newtype patternTypes are documentation that the compiler checks:
any/interface{} to specific types where possibleNever skip this phase. Simplification that breaks behavior is not simplification.
If tests fail or behavior diverges: revert the specific change, don't try to fix the test.
Present changes as a structured summary. This is important — the developer needs to understand and trust what changed before committing.
For each file modified, provide:
## <filename>
### Changes
- [Critical] Removed unreachable error branch in `parse_config` (dead code after L42 guard)
- [High] Extracted `validate_credentials()` from 60-line `handle_login()` (was 3 responsibilities)
- [Medium] Renamed `d` → `document`, `proc` → `process_batch`
### Complexity Delta
- `handle_login`: 4 levels nesting → 2, 8 branches → 5
- `parse_config`: removed 12 lines of dead code
### Risk Assessment
- Low risk: all changes are structural, no logic modifications
- Tests: 47/47 passing
Adjust verbosity to scope. Single-function cleanup gets a one-liner. Multi-file refactor gets the full report.
These are hard rules. Do not violate them regardless of how much cleaner the code would look:
The user may specify different modes. If they don't, default to standard.
| Mode | Scope | Severity Threshold | Test Requirement |
| ---------- | ------------------------------ | ------------------------ | ---------------------------- |
| quick | Single file or function | Critical + High only | Tests recommended |
| standard | Recent git changes | Critical + High + Medium | Tests required if they exist |
| deep | Entire module/package | All severities | Tests mandatory |
| surgical | User-specified lines/functions | All severities | Manual trace sufficient |
The user can specify mode by saying things like "just do a quick pass" or "deep clean this module".
Push back (politely) if:
For language-specific idiom guidance, read the appropriate reference file:
references/python.md — Python-specific patterns, anti-patterns, and stdlib alternativesreferences/go.md — Go idioms, error handling patterns, and interface designreferences/typescript.md — TypeScript/JavaScript patterns, type narrowing, and module designreferences/rust.md — Rust idioms, ownership patterns, and iterator usageOnly load the reference file for the language(s) in the current scope. These provide detailed pattern catalogs that supplement the general methodology above.
| Rationalization | Reality | |---|---| | "It's readable enough" | "Enough" is not a standard — if the next developer needs to re-read a function 3 times, it's not readable | | "Refactoring risks regressions" | Not refactoring risks accumulating debt — run the test suite before and after, that's what tests are for | | "This is how the codebase has always done it" | Consistency with a bad pattern is still bad — improve incrementally, don't preserve anti-patterns | | "The performance might get worse" | Benchmark before and after — most readability refactors have zero performance impact; premature optimization is the root of all evil | | "It's not broken, don't fix it" | Refining isn't fixing — it's making working code maintainable, testable, and understandable for the next person | | "I'll refactor the whole module later" | Incremental refinement works; big-bang rewrites fail — improve what you touch now |
ruff check + mypy --strict or tsc --noEmit + eslinttesting
Manages dependent branch stacks and stacked pull requests using safe Git topology rules. Triggers on: "create stacked PRs", "publish this stack", "sync my PR stack", "rebase this stack", "merge the stack", "retarget child PRs", "split this branch into stacked PRs", "validate this stack", "cleanup stacked branches". Use when local branches or one source branch need to become a dependency-ordered PR stack with correct parent bases, validation, synchronization, merge order, and cleanup.
development
Scaffolds per-repository agent context so coding agents share the same issue tracker rules, triage label vocabulary, domain glossary, ADR layout, and handoff conventions. Triggers on: "set up project context", "configure agent docs", "create CONTEXT.md", "setup agent workflow", "agent issue tracker setup", "triage labels", "domain glossary for agents". Use when a repo needs durable context files before planning, triage, debugging, TDD, architecture review, or multi-agent implementation.
testing
Produces phased task boards from feature requests: dependency-mapped work items, parallelization flags, risk flags, edge cases, test matrices. Triggers on: "decompose this feature", "task breakdown with dependencies", "phased implementation plan", "work breakdown structure". NOT for effort estimates, use estimate-calibrator.
development
Hypothesis-driven debugging with ranked hypotheses, git bisect strategy, instrumentation planning, and minimal reproduction design. Triggers on: "debug this systematically", "root cause analysis", "bisect this bug", "rank hypotheses", "isolate this issue", "minimal reproduction". NOT for general reasoning.