Best for
- Use when reducing technical debt, planning codemods, applying strangler migrations, or tightening CI guardrails around risky changes.
vasilyu1983/AI-Agents-public/frameworks/shared-skills/skills/qa-refactoring/SKILL.md
Safe refactoring with behavior preservation. Use when reducing technical debt, planning codemods, applying strangler migrations, or tightening CI guardrails around risky changes.
Decision brief
Use this skill to refactor safely: preserve behavior, reduce risk, and keep CI green while improving maintainability and delivery speed.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Declared | Source record | Install path and trigger |
| Claude Code | Declared | Source record | Install path and trigger |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/vasilyu1983/AI-Agents-public --skill "frameworks/shared-skills/skills/qa-refactoring"Inspect the Agent Skill "qa-refactoring" from https://github.com/vasilyu1983/AI-Agents-public/blob/53f6cb73ea53a2646e3e7d4665062ad66f3683ac/frameworks/shared-skills/skills/qa-refactoring/SKILL.md at commit 53f6cb73ea53a2646e3e7d4665062ad66f3683ac. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
If key context is missing, ask for: what must not change (invariants), risk level (money/auth/migrations/concurrency), deployment constraints, and the smallest boundary that can be protected by tests.
1. Establish the safety net, boundaries, and rollback shape. 2. Choose the refactoring strategy and smallest change slice. 3. Make the change, verify behavior, and stop if the safety bar drops below acceptable risk. 4. Capture the next slice instead of expanding scope mid-pass.
Verify in layers, cheapest first: type check → lint → unit/characterization → contract/integration → mutation-score gate on the touched boundary → canary/shadow for production-critical paths. Stop widening scope the mom…
The line-count trigger is adapted from addyosmani/agent-skills (MIT), commit 7676817, 2026-08-09.
Establish baseline: get main green; reproduce the behavior you must preserve.
Permission review
The documentation asks the agent to create, modify, or delete local files.
Before pointing an agent at a legacy repo, build the acceptance gate first and never let the agent modify it; graph the repo to choose the seam instead of letting the agent pick what it understands best. See [references/brownfield-agent-looThe documentation includes network, browsing, or remote request actions.
Use web search or web fetch to verify current external facts, versions, pricing, deadlines, regulations, or platform behavior before final answers.Evidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 96/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 82 | Source | Repository attention, not individual Skill quality |
| Compatibility | 2 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Use this skill to refactor safely: preserve behavior, reduce risk, and keep CI green while improving maintainability and delivery speed.
Defaults: baseline first, smallest safe step next, and proof via tests/contracts/observability instead of intuition.
main green; reproduce the behavior you must preserve.main green; reproduce the behavior you must preserve.| Risk | Examples | Minimum required safety net |
|---|---|---|
| Low | rename, extract method, formatting-only | unit tests + lint/type checks |
| Medium | moving logic across modules, dependency inversion, codemods with narrow blast radius | unit + integration/contract tests at boundary |
| High | auth/permission paths, concurrency, migrations, money/data-loss paths, large-scale automated rewrites | integration + contract tests, observability checks, rollout + rollback plan |
git bisect viable: avoid mixed "mechanical + semantic" changes unless necessary.Do:
Avoid:
The line-count trigger is adapted from addyosmani/agent-skills (MIT), commit 7676817, 2026-08-09.
Refactoring is an investment decision, not a moral obligation — weigh it like one.
git blame/git log -p the lines to find the commit and linked ticket/PR that added them, and check for a comment explaining the rationale. Only delete once you can state why the fence was put up, not just that you can't currently see a reason for it.Prompts framed as "refactor this" fail agents in a specific way: the agent notices a local improvement opportunity and takes it, silently expanding scope from "same behavior, better structure" to "same behavior, better structure, plus a few fixes I noticed along the way." Watch for, and gate against, these failure modes:
except/catch, turning a silent failure into a raised exception (or the reverse), or changing a default on an error path. Nearly invisible in review because the "refactored" code reads as cleaner.> becomes >= (or vice versa) while consolidating near-duplicate conditionals.Gate before merging an agent-authored "refactor":
| Task | Tool/Pattern | Command/Approach | When to Use |
|---|---|---|---|
| Long or mixed-concern function | Extract Method | Split into smaller functions | Single function mixes validation, orchestration, and side effects |
| Large or low-cohesion class/module | Split Class / Extract Module | Create focused units with narrower responsibilities | One type owns unrelated workflows or too many dependencies |
| Duplicated code | Extract Function/Class | DRY principle | Same logic in multiple places |
| Complex conditionals | Replace Conditional with Polymorphism | Use inheritance/strategy pattern | Switch statements on type |
| Long parameter list | Introduce Parameter Object | Create DTO/config object | Functions with >3 parameters |
| Legacy code modernization | Characterization Tests + Strangler Fig | Write tests first, migrate incrementally | No tests, old codebase |
| Large mechanical rewrite | Codemod / AST transform | Dry-run, sample diff review, staged batch rollout | Renames, API migrations, repetitive edits across many files |
| Java framework migration (Spring Boot, Java version) | OpenRewrite recipe via Moderne CLI or MCP | mod run . --recipe UpgradeSpringBoot_3_4 | AI agents can invoke 5,000+ OpenRewrite recipes as deterministic tool calls |
| Automated quality gates | Compiler + linter + contract checks | CI pipeline with fail-fast checks and artifacts | Prevent silent regression during refactors |
| Technical debt tracking | Debt register + static analysis | Track trends, hotspots, and owners | Prioritize refactoring work |
Code issue: [Refactoring Scenario]
├─ Code Smells Detected?
│ ├─ Duplicated code? → Extract method/function
│ ├─ Mixed concerns in one function? → Extract smaller methods
│ ├─ Low cohesion / too many dependencies? → Split into focused classes or modules
│ ├─ Long parameter list? → Parameter object
│ └─ Feature envy? → Move method closer to data
│
├─ Legacy Code (No Tests)?
│ ├─ High risk? → Write characterization tests first
│ ├─ Large rewrite needed? → Strangler Fig (incremental migration)
│ ├─ Unknown behavior? → Characterization tests + small refactors
│ └─ Production system? → Canary/shadow rollout + monitoring
│
├─ Repetitive Multi-File Edit?
│ ├─ Compiler/IDE can prove rename? → Use native refactor tooling
│ ├─ Pattern is syntactic/semantic? → Use codemod or AST rewrite
│ └─ Blast radius is large? → Dry-run + sample review + batch rollout
│
├─ Quality Standards?
│ ├─ New project? → Setup compiler/linter/test gates
│ ├─ Existing project? → Add pre-commit hooks + CI checks
│ ├─ Complexity hotspots? → Add targeted guardrails and characterization tests
│ └─ Technical debt? → Track in register with owners and review cadence
Refactoring request
-> State behavior that must not change and rollback boundary
-> Capture baseline with tests, contracts, metrics, or characterization output
-> Choose the smallest behavior-preserving step
-> Apply native refactor tooling, codemod, or manual edit as appropriate
-> Run targeted verification before widening scope
-> Retire debt, flags, dead code, or guardrails only with evidence
## Workflow, ## Core QA (Default), and ## Decision Tree: Refactoring Strategy for the baseline sequence## Operational Deep Dives, ## Templates, and ## Resources for deeper materials## Related Skills for testing, architecture, and code-review handoffs| Skill | Purpose |
|---|---|
| qa-debugging | Debugging production issues and test flakes |
| software-code-review | Code review process and checklists |
| software-architecture-design | Architecture design and redesign decisions |
| qa-testing-strategy | Test strategy and coverage planning |
| data-sql-optimization | Performance tuning, SQL, and query plans |
CC-*) for citationRULE-01–RULE-13, decision trees, and operational proceduresSee references/operational-patterns.md for detailed refactoring catalogs, codemod rollout patterns, quality gates, technical debt playbooks, and legacy modernization steps.
Use copy-paste templates in assets/ for checklists and quality-gate configs:
Use deep-dive guides in references/ (load only what you need):
Do:
mod CLI or MCP server) over hand-written codemods — recipes are deterministic and version-aware; AI agents can invoke them directly as tool calls.Avoid:
See data/sources.json for curated external references.
Before applying this skill on a non-trivial task, read learnings.consolidated.md in this directory (and learnings.md if present).
After applying it, if you encountered a pattern worth remembering, a mistake worth preventing, or a domain fact that surprised you, append one dated bullet to learnings.md via agents-skills-feedback-loop/scripts/append_learning.py. Do not modify SKILL.md itself.
Frequently asked questions
Use this skill to refactor safely: preserve behavior, reduce risk, and keep CI green while improving maintainability and delivery speed.
The source record exposes this install command: npx skills add https://github.com/vasilyu1983/AI-Agents-public --skill "frameworks/shared-skills/skills/qa-refactoring". Inspect the command and pinned source before running it.
The pinned source record declares support for: codex, claude code.
Static rules flagged write-files, network in the source; the page lists the matching lines and excerpts.
Alternatives
vasilyu1983/AI-Agents-public
Guides iOS testing with XCTest, XCUITest, Swift Testing, simctl, and xcresult. Use when choosing destinations, controlling flakes, or parsing test artifacts for native apps.
PramodDutta/qaskills
Gate RAG pipelines in CI with versioned golden eval sets, per-metric thresholds, baseline drift detection, and a build that fails when retrieval or answer quality regresses.
PramodDutta/qaskills
Generate comprehensive test cases from state machine models covering all states, transitions, guard conditions, and invalid transition attempts for workflow-heavy features
lobu-ai/lobu
Set up new Lobu agents end to end and operate existing Lobu projects and memory: interview, scaffold, validate, authenticate, connect feeds, execute operations, and test Automations.