graph-refactor
Tech debt management and refactoring audit using SQALE method, complexity analysis, dead code detection, and KISS/YAGNI/DRY enforcement
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Tech debt management and refactoring audit using SQALE method, complexity analysis, dead code detection, and KISS/YAGNI/DRY enforcement
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Accessibility compliance audit using WCAG 2.2 AA standards, ARIA validation, screen reader testing, keyboard navigation, color contrast analysis, and i18n readiness
Execute the ANALYZE phase of the lifecycle via the `agf` CLI — PRD creation, requirements, Definition of Ready (7 checks), cross-project learning
API governance and design audit using OpenAPI/Swagger spec generation, REST maturity model, contract validation, and breaking change detection
Architecture governance using C4 Model, ADR lifecycle, Architecture Fitness Functions, layer boundary enforcement, and drift detection
Human-in-the-loop PLANNING skill — investigates the project (graph + git + harness/gaps) and runs the whole ANALYZE→DESIGN→PLAN chain in one faceted loop to produce a COMPLETE PRD injected as graph backlog (epics, tasks, testable AC) for a separate agent to implement. Applies the project's planning methodologies — Impact Mapping + OKR per epic, JTBD, MoSCoW, WSJF/Cost-of-Delay, User Story Mapping, Example Mapping (Rules/Examples → Given-When-Then AC), SPIDR splitting, INVEST, Definition of Ready, Risk Matrix; the full catalogue lives in the skill body. Stops for the human after each complete PRD and iterates the next cycle from the project's own findings (dogfood). Does NOT implement. Triggers — graph-backlog-generation, gerar backlog, criar PRD, planejar feature, detalhar épico, novo ciclo, "plan the next thing", "what should we build next".
Automated bug discovery through static analysis, LSP diagnostics, pattern detection, regression hotspot analysis, and error catalog mining
| name | graph-refactor |
| description | Tech debt management and refactoring audit using SQALE method, complexity analysis, dead code detection, and KISS/YAGNI/DRY enforcement |
| triggers | ["graph-refactor"] |
| version | 2.0.0 |
| author | Diego Nogueira |
| date | "2026-06-21T00:00:00.000Z" |
Tech debt management and refactoring audit using SQALE method, complexity analysis, dead code detection, and KISS/YAGNI/DRY enforcement. Identifies code that is too complex, duplicated, unused, or over-engineered, and produces a prioritized refactoring plan tracked in the execution graph.
complexity scan → dead code detection → duplication analysis → KISS/YAGNI audit → tech debt scoring → refactoring order → test verification → report → write_memory
Measure cyclomatic complexity per function. Use agf code def|refs|impact for symbol-level analysis, and
agf lint-files for the 800-line ceiling. Dead capability is debt too: agf wire-dormant lists
exported-but-unreachable code and agf wire-check fails when it grows.
| Complexity | Level | Action |
|---|---|---|
| 1-5 | Simple | No action |
| 6-10 | Moderate | Monitor |
| 11-20 | Warning | Schedule refactor |
| >20 | Critical | Refactor immediately |
Also flag: nesting >3 levels, functions >50 lines, parameters >5, files >500 lines.
npx eslint src/ --rule '{"no-unused-vars":"error","no-unreachable":"error"}'
Detect blocks >10 lines appearing in multiple files. Target: <3% duplication. DRY violation types: inadvertent (stored twice), impatient (copy-paste), interdeveloper (same utility twice).
Flag: single-impl interfaces, abstract classes with one subclass, unused config flags, functions with zero callers, speculative code paths. Ask: "Does this complexity serve a current requirement?" If not → remove.
Full formula:
debt_ratio = Σ remediation_time / (LOC × 30min)
| Grade | Debt Ratio | Meaning |
|---|---|---|
| A | <5% | Healthy |
| B | 6-10% | Manageable — address in next sprint |
| C | 11-20% | Concerning — allocate 20% capacity |
| D | 21-50% | High — dedicated cleanup sprint |
| E | >50% | Critical — new features blocked |
Debt categories:
| Category | Difficulty | Examples |
|---|---|---|
| Architecture | Hard | Circular deps, layer violations, module boundaries |
| Design | Medium | Missing interfaces, tight coupling, wrong abstractions |
| Code | Easy | Long functions, magic numbers, naming, duplication |
Hotspot analysis (files with high churn AND high debt = top priority):
git log --format=format: --name-only --since="90 days" -- src/ | sort | uniq -c | sort -rn | head -20
Never refactor randomly. Apply this sequence — it matches both Feathers' legacy code loop and Fowler's four refactoring types.
Feathers' Legacy Code Loop ([[feathers-legacy-code]]):
Fowler's Four Refactoring Types ([[fowler-refactoring]] ch02), in priority order:
Never mix refactoring with behavior change. ([[fowler-refactoring]] ch02 — Fowler's core discipline)
Practical enforcement:
refactor: extract pricing logic into PriceCalculatorfeat: add volume discount tierWhen a refactoring target has no tests, use Feathers' Seam Model to break dependencies before refactoring. ([[feathers-legacy-code]] ch04)
Three seam types, in preference order:
| Seam Type | How It Works | Enabling Point | Use When |
|---|---|---|---|
| Object Seam | Method call behavior depends on which object receives it | Object creation site (constructor, factory, parameter) | Always prefer this first |
| Link Seam | Entire class/library resolved at link time | Build configuration | Pervasive dependency spanning many files |
| Preprocessing Seam | C/C++ macro replaces text before compile | #define / #ifdef | Last resort; invisible to code readers |
Object Seam workflow:
Per finding, select the specific Fowler move:
| Pattern | Refactoring | Effort |
|---|---|---|
| Long function | Extract Function | XS-S |
| Deep nesting | Guard Clauses / Early Return | XS |
| Duplicate code | Extract Shared Utility | S-M |
| Large class/file | Extract Class, Split Module | M |
| Complex conditional | Replace Conditional with Polymorphism | M-L |
| God object | Decompose into focused modules | L |
| Tight coupling | Introduce Interface / Dependency Injection | M-L |
| Feature Envy | Move Function to where the data lives | S |
| Repeated Switches | Replace Conditional with Polymorphism | M |
| Data Clumps | Extract Class, Introduce Parameter Object | S |
Create graph nodes for M/L refactorings:
agf node add --title "DEBT: <what> em <file>" --type task --tags "tech-debt,<category>" --ac "<observable outcome>"
Before ANY refactoring move:
npm test — must be green before first structural changeSafety protocol (Fowler):
Scoring:
Save findings:
agf memory write tech-debt-audit-<date> --content "<report>"
[[fowler-refactoring]] — Two Hats (ch02), smell catalog (ch03), refactoring mechanics (ch06-ch12), Preparatory Refactoring, Self-Testing Code prerequisite[[feathers-legacy-code]] — Seam Model (ch04), Characterization Tests (ch13), Sprout/Wrap (ch06), Legacy Code Change AlgorithmEconomia de tokens. Os levers compartilhados por todas as skills —
--select,agf retrieve-command,agf exec chain, reuso antes de criação — vivem em_shared.md→ Token Economy. Fonte única: um parágrafo repetido em trinta arquivos é o trigésimo primeiro que envelhece sozinho.
Não precisa de flags. CLI gerencia compressão automaticamente com --ai ativo.
Consulte comandos com agf retrieve-command "<intenção>".
Ver _agf-rag.md para detalhes.