agentleFS
n24q02mn24q02m/better-code-review-graph/skills/refactor-check/SKILL.md

refactor-check

Skill76 starsChanged 7 months agoApache-2.0View on GitHub

Safety analysis before refactoring -- dependency graph, test coverage, public API exposure, blast radius verdict.

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 7 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Command surface: run the local CLI through the coding harness shell.

    line 11
  2. Very specific:

    use --pattern callees_of to see what this calls

    line 20
  3. Very specific:

    use --pattern imports_of to see what this imports

    line 21
  4. Very specific:

    If it is a class, also query --pattern inheritors_of and --pattern children_of

    line 22
  5. Very specific:

    Check if the target is exported from a package __init__.py, index.ts, or similar

    line 30
  6. Distinctive:

    Check if the target is referenced from outside its own module/package

    line 31
  7. Distinctive:

    Check if the target appears in documentation or type stubs

    line 32
  8. Distinctive:

    Before renaming a function, class, or method

    line 95
  9. Distinctive:

    Before changing a function signature (parameters, return type)

    line 96
  10. Distinctive:

    Before moving code to a different module/package

    line 97
  11. Distinctive:

    Before splitting a class or merging functions

    line 98
  12. Distinctive:

    Before deleting code that might still be referenced

    line 99

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Refactor Check

Analyze whether a refactoring is safe BEFORE making changes. Produces a verdict with specific risks and mitigation steps.

Command surface: run the local CLI through the coding harness shell. Examples use the installed crg command; from a source checkout, prefix it with uv run. No MCP mapping is required.

Steps

  1. Get the full dependency graph for the target:
    • crg graph build --base HEAD --repo-root "<path>" to index current working changes
    • crg query query --pattern callers_of --target "<name>" --repo-root "<path>" -- who calls this
    • use --pattern callees_of to see what this calls
    • use --pattern imports_of to see what this imports
    • If it is a class, also query --pattern inheritors_of and --pattern children_of
  2. Identify test coverage:
    • crg query query --pattern tests_for --target "<name>" --repo-root "<path>" -- direct tests
    • For each caller, also query tests_for to see if callers have integration tests covering this function indirectly
    • Record: number of direct tests, number of callers with tests, number of callers without tests
  3. Flag public API exposure:
    • Check if the target is exported from a package __init__.py, index.ts, or similar
    • Check if the target is referenced from outside its own module/package
    • Check if the target appears in documentation or type stubs
    • Public API = any function/class importable by external consumers
  4. Estimate blast radius:
    • crg query impact --changed-files "<target-file>" --repo-root "<path>" -- file-level impact analysis around the target
    • Count: total impacted files, total impacted functions, depth of dependency chain
    • Identify any impacted files outside the immediate package/module
  5. Produce verdict:

    ## Refactor Safety: <name>
    
    ### Target
    - **Location**: <file_path>:<line>
    - **Type**: function / class / method
    - **Public API**: Yes / No
    
    ### Dependency Summary
    - **Callers**: N functions depend on this
    - **Callees**: Calls M other functions
    - **Inheritance**: N subclasses (if class)
    
    ### Test Coverage
    - **Direct tests**: N tests
    - **Caller tests**: M/K callers have tests covering this path
    - **Coverage gaps**: <list uncovered callers>
    
    ### Blast Radius
    - **Impacted files**: N
    - **Impacted functions**: M
    - **Max depth**: K hops
    
    ### Verdict: SAFE / NEEDS MIGRATION / DANGEROUS
    
    **SAFE** -- Low blast radius (<5 files), good test coverage, no public API exposure.
    Make the change, run tests, done.
    
    **NEEDS MIGRATION** -- Public API or moderate blast radius (5-15 files).
    Recommended approach:
    1. Create new version alongside old
    2. Migrate callers incrementally
    3. Deprecate old version
    4. Remove after all callers migrated
    
    **DANGEROUS** -- High blast radius (>15 files), poor test coverage, or public API with external consumers.
    Specific risks:
    - <risk 1 with affected files>
    - <risk 2 with affected files>
    Mitigation: <steps to reduce risk before proceeding>

Verdict Criteria

ConditionVerdict
<5 impacted files, not public API, >80% caller test coverageSAFE
5-15 impacted files OR public API with known consumersNEEDS MIGRATION
>15 impacted files OR public API with unknown consumers OR <50% test coverageDANGEROUS
Any external package/library depends on itDANGEROUS

When to Use

  • Before renaming a function, class, or method
  • Before changing a function signature (parameters, return type)
  • Before moving code to a different module/package
  • Before splitting a class or merging functions
  • Before deleting code that might still be referenced

Download now (ZIP)

  • Other versions2 projects use a version of this.

    Word for word · 1

    1. n24q02m/crg★ 76100% same

    Edited · 0

    None found.

    Wrote their own version · 1

    1. urunimi/skills★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository10 other files it gives its agents.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

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.