agentleFS
y-miyazakiy-miyazaki/config/.agents/skills/refactor/SKILL.md

refactor

Skill1 starsChanged 9 days agoApache-2.0View on GitHub

Behavior-preserving structural refactors with verification gates. Use in conversation when surveying or applying structural refactors. Also the loop entry skill when automation supplies hints (duplication_block, oversized_unit). Interactive default is survey only; apply edits when the request asks for changes to be made (for example fix, apply, or update) or automation sets agent_edit_allowed in Constraints. Not for lint-only style, features, behavior-changing bugfixes, or upgrades.

196 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use ascii-diagram, debug-fix and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SethGammonSkill

    ascii-diagram

    Generate perfectly aligned ASCII diagrams — architecture, flow, sequence, box-and-arrow. Uses a programmatic character-grid approach so alignment is guaranteed by math, not token prediction. Includes post-render verification.

    Also in 4 projects that use this

  • zebbernSkill

    debug-fix

    Find and fix a bug or issue — from any source (GitHub issue, error message, user report, or observed behavior)

    Also in 4 projects that use this

  • parcadeiSkill

    agent-context-isolation

    Agent Context Isolation

    Also in 3 projects that use this

  • parcadeiSkill

    agentica-infrastructure

    Reference guide for Agentica multi-agent infrastructure APIs

    Also in 3 projects that use this

  • +8 more from parcadei

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 169 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When intent is unclear, survey and offer to apply — edits are harder to undo than a report.

    line 71
  2. Very specific:

    When agent_edit_allowed is true, resolve agent_edit_target: interactive → fix.

    line 73
  3. Very specific:

    If detect JSON is absent, run scripts/detect_refactor.sh with the resolved scope (default --scope all.

    line 104

“Common” is measured: kept by at least 6 in 10 of the 169 edited versions of this file we could read. “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

UTILITY SKILL — structural refactor survey and apply, not feature work.

Input

  • Interactive (required): paths/symbols and optional mode — constraints in ## Constraints or category-scope.md
  • Automation (optional): detect JSON with hints[] in prompt — from a caller or optional skill detect script; not required for interactive runs. Read agent_edit_allowed and agent_edit_target from ## Constraints per category-automation-envelope.md

Path allowlist, when present, arrives in ## Constraints.

Output Specification

Refactor report per common-output-format.md. Survey shape when no files are edited; apply shape when edited — within category-scope.md. Automation path: common-output-format-automation.md and category-automation-envelope.md.

Execution Scope

USE FOR:

  • Survey structural candidates; dedupe, extract/inline, clarify, shallow moves; automation hints; architecture Phase A/B; characterization tests

DO NOT USE FOR:

  • Lint/style-only; features/API/behavior fixes; cross-boundary apply; platform-wide architecture refactors; external debt-survey apply input

Reference Files Guide

  • common-checklist.md (always read)
  • common-output-format.md (always read)
  • category-scope.md (always read)
  • category-contract.md (always read)
  • category-detect-scope.md (read on interactive path)
  • category-verification.md (read when agent_edit_allowed is true)
  • category-techniques.md (read when agent_edit_allowed is true)
  • category-input-schema.md (read when structured mode JSON, automation detect JSON, or the optional detect script is run)
  • category-automation-envelope.md (read on automation path)
  • common-output-format-automation.md (read on automation path)
  • common-troubleshooting.md (read on failure)
  • category-pr-body-links.md (read when synthesizing the PR body)
  • assets/pr-body-template.md and assets/pr-body-template-survey.md (read when synthesizing the PR body)

Workflow

Phases, modes, depth tiers, and intent: category-contract.md. Self-check gates: common-checklist.md.

Canonical sequence: resolve agent_edit_allowed → Phase A (discover/classify; emit only when stopping) → Phase B only when edit-authorized → emit one result shape (OUT-01).

Resolve agent_edit_allowed before Phase B. When structured JSON mode is present (category-input-schema.md), it wins over the interactive rows: survey → false; apply → true. Otherwise use the table. An imperative with a target ("refactor scripts/a.sh", "deduplicate these helpers") asks for changes; "use refactor on X" or "what could be refactored in X" only names the skill or asks to look, so it stays survey.

Sourceagent_edit_allowed
Interactive — default: the request asks to look, check, triage, or survey, or only names the skillfalse — survey only; do not edit files
Interactive — the request asks for changes to be made (for example fix, apply, 修正して, 適用して, update, add)true
Interactive — follow-up after a survey asking to applytrue
Automation — ## Constraintsagent_edit_allowed: true or agent_edit_allowed: false from category-automation-envelope.md

When intent is unclear, survey and offer to apply — edits are harder to undo than a report.

When agent_edit_allowed is true, resolve agent_edit_target: interactive → fix; automation → from ## Constraints. Do not branch on other caller metadata. Before Phase B, load category-techniques.md.

Phase B runs only when agent_edit_allowed is true and agent_edit_target is fix. Architecture without approved_slice never enters Phase B (INTENT-02).

Phase A — Survey (always)

Discover and classify only. Emit a final report from Phase A only when this run will not enter Phase B (see Interactive / Automation paths).

  1. Resolve scope (category-scope.md); parse structured/detect JSON when present (category-input-schema.md).
  2. Classify intent (category-contract.md).
  3. Architecture without approved_slice: emit survey shape with ### Architecture Proposal only; stop (INTENT-02). Do not treat as zero-actionable no-op.
  4. Discover candidates (SURVEY-01): structural → all in-scope; architecture Phase B → only the approved_slice. Read targets before classifying (SURVEY-03); route apply-worthy → Candidates, else → Watch (SURVEY-02).
  5. Structural zero actionable → emit survey no-op per common-output-format.md (Overview explains no-op); stop.

Phase B — Apply (agent_edit_allowed: true and agent_edit_target: fix)

  1. For each apply candidate: one technique (category-techniques.md); gate (category-verification.md); on failure revert → Deferred; continue (APPLY-01).
  2. Re-run gates on touched areas; emit apply shape; reconcile with git diff --name-only (OUT-01).

Automation path (hints[] in detect JSON)

  1. Parse detect JSON; read agent_edit_allowed / agent_edit_target from ## Constraints.
  2. Empty/skip → emit survey no-op per common-output-format.md (Overview explains no-op) + Session Metrics; stop.
  3. Phase A on all hints[] (structural only — no architecture Phase A/B).
  4. agent_edit_allowed: false or agent_edit_target ≠ fix → emit survey shape + Session Metrics (note expected agent_edit_target: fix when mismatched); no Phase B.
  5. Else → Phase B; emit apply shape + Session Metrics (category-automation-envelope.md).

Interactive path

  1. Resolve agent_edit_allowed (table above). Load category-detect-scope.md.
  2. Resolve universe from the prompt (default = REFACTOR_SCAN_GLOBS / skill defaults). If the user named paths/globs, narrow the universe before detect.
  3. If detect JSON is absent, run scripts/detect_refactor.sh with the resolved scope (default --scope all; set REFACTOR_SCAN_GLOBS for a temporary universe). On non-zero exit or status: "error", read stdout and stop.
  4. Phase A: classify every hints[] entry and Agent-complement structural candidates (read targets — SURVEY-03). Architecture without approved_slice stops inside Phase A step 3.
  5. Empty detect alone is not a no-op if complement found apply-worthy or watch-worthy work.
  6. agent_edit_allowed: false or agent_edit_target ≠ fix → emit survey shape; stop.
  7. Else → Phase B; emit apply shape.

Error Handling

ConditionSeverityAction
Detect script non-zero exit or status: "error" (when invoked)FatalRead stdout; stop — do not treat as success-path detect JSON
Automation: empty/skipInfoEmit survey no-op (Overview explains no-op); stop
Survey: zero candidatesInfoEmit survey no-op (Overview explains no-op); stop
Architecture request without sliceRecoverableArchitecture proposal only; stop
Lint-primary or feature/API candidateRecoverableWatch on candidate; skip apply
Weak or failed gate for one candidateRecoverableRevert that candidate; Deferred; continue
Cross-boundary or out-of-scope targetRecoverableWatch on candidate; skip apply
Edit requested but ## Constraints set agent_edit_allowed: falseInfoSurvey only; note that the caller Constraints disallow edits
agent_edit_allowed true with agent_edit_target not fixRecoverableSurvey only; note expected agent_edit_target: fix

Examples

  • Prompt: Survey structural refactor candidates in this package
  • Result: Survey report per references/common-output-format.md; apply only when agent_edit_allowed is true, agent_edit_target is fix, and candidates are marked apply.

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.