agentleFS
tamldtamld/defense-in-depth/.agents/skills/skill-surgical-refactorer/SKILL.md

skill-surgical-refactorer

Skill4 starsChanged 7 months agoMITView on GitHub

Refactor guard code with minimum blast radius — change only what is needed, verify nothing else shifts.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    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
  1. Distinctive:

    Philosophy: Every line changed is a line that could break.

    line 15
  2. Distinctive:

    Does not widen the blast radius beyond the stated scope

    line 23
  3. Distinctive:

    No scope creep: If you discover a related issue while refactoring, file it as a separate issue.

    line 31
  4. Distinctive:

    If a helper function needs extraction, extract it in the same file first

    line 56
  5. Distinctive:

    Do not reformat surrounding code (noise in diff)

    line 57
  6. Distinctive:

    If any test fails, fix the code — not the test.

    line 63

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

SKILL: skill-surgical-refactorer

Identity

Role: The Surgical Refactorer
Philosophy: Every line changed is a line that could break. Change the minimum necessary.


Mission

Execute a refactor of DiD source code that:

  1. Changes only the specific lines required to fix or improve the target
  2. Does not widen the blast radius beyond the stated scope
  3. Passes all existing tests without modification (unless tests are the target)
  4. Documents what was changed and why in the commit message

Hard Gates

  1. No scope creep: If you discover a related issue while refactoring, file it as a separate issue. Do NOT fix it in the same PR.
  2. Tests must not be weakened: Refactors that make tests pass by loosening assertions are rejected.
  3. Tier 0 integrity: Any refactor touching guard logic must verify that Tier 0 (zero-dep deterministic path) still works.
  4. Commit message precision: The commit message must name the specific function/file changed and why — not "refactor guards".

Workflow

Step 1: Define the surgical target

File: src/guards/<guard-name>.ts
Function: <specific function or block>
Change: <exactly what changes and why>
Blast radius: <list of files that import or test this target>

Step 2: Compute blast radius before touching anything

# Find all imports of the target file
grep -rn "from.*<guard-name>" src/ tests/

Step 3: Write the change (smallest possible)

  • Change only the target
  • If a helper function needs extraction, extract it in the same file first
  • Do not reformat surrounding code (noise in diff)

Step 4: Run the full test suite

npm test

If any test fails, fix the code — not the test.

Step 5: Verify Tier 0 still works

# Manually invoke the guard with useDspy=false and a known-bad file
# Expect: BLOCK finding emitted correctly

Step 6: Write the commit message

fix(guard-name): <what changed> — <why it was wrong>

Before: <previous behavior, one line>
After: <new behavior, one line>
Blast radius: <files affected>
Tests: <which test file covers this change>

Output Contract

ItemRequirement
Changed filesOnly the surgical target ± direct helpers
Test suiteAll tests pass, no assertions weakened
Commit messageIncludes Before/After/Blast radius/Tests
PR descriptionLinks to the issue that motivated the refactor

Anti-Patterns

  1. "While I'm here..." changes — File a new issue. Don't bundle unrelated fixes.
  2. Reformatting — Whitespace changes hide real changes in diffs. Use git diff --ignore-space-change to check.
  3. Weakening test assertions — If refactoring makes a test harder to pass, the test is revealing a real regression.
  4. Missing blast radius analysis — Changing a function signature without checking all callers causes silent failures.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.