Agent-design-language refactoring-helper
Plan and bound source-grounded refactoring work by turning a concrete code surface into small behavior-preserving slices with invariants, risk inventory, validation commands, rollback notes, and residual risks, while stopping before broad rewrites or silent behavior changes.
git clone https://github.com/danielbaustin/agent-design-language
T=$(mktemp -d) && git clone --depth=1 https://github.com/danielbaustin/agent-design-language "$T" && mkdir -p ~/.claude/skills && cp -r "$T/adl/tools/skills/refactoring-helper" ~/.claude/skills/danielbaustin-agent-design-language-refactoring-helper && rm -rf "$T"
adl/tools/skills/refactoring-helper/SKILL.mdRefactoring Helper
Use this skill when a messy code surface needs a safer refactoring path before implementation. The skill creates a behavior-preserving refactor plan, bounded refactor plans, and execution slices; it does not turn vague cleanup instincts into broad rewrites.
Quick Start
- Confirm the bounded code surface:
- exact files, modules, diff, or issue scope
- current behavior to preserve
- explicit behavior changes, if any
- Identify invariants before edits:
- public API behavior
- persistence or artifact format
- ordering or determinism guarantees
- security/privacy boundaries
- compatibility contracts
- Run the deterministic helper when local filesystem access is available:
scripts/plan_refactor.py <refactor-root> --out <artifact-root>
- Review the refactor plan, risk inventory, validation plan, slices, and rollback notes.
- Stop unless the operator explicitly asks to implement one bounded slice.
Required Inputs
At minimum, gather:
modetargetcurrent_behaviorrefactor_intentpolicy
Supported modes:
plan_refactorslice_refactorreview_refactor_planprepare_refactor_handoff
Useful policy fields:
behavior_change_allowedmax_slice_countrequire_tests_before_editsrequire_rollback_notesstop_before_broad_rewritewrite_refactor_artifact
If no bounded target is supplied, stop and report
not_run. If behavior change
is requested, name it explicitly and keep it separate from behavior-preserving
refactor work.
Refactor Slice Rules
Each slice should include:
- the smallest coherent code surface
- behavior-preservation intent or explicit behavior-change note
- invariants that must remain true
- likely changed files
- validation commands and what they prove
- rollback notes
- residual risk and follow-on slices
Prefer sequencing that reduces blast radius:
- characterization or contract tests
- extraction or naming cleanup
- dependency boundary tightening
- internal data-shape cleanup
- deletion of dead paths only after proof exists
Output
Write Markdown and JSON artifacts when an output root is available.
Default artifact root:
.adl/reviews/refactoring-helper/<run_id>/
Required artifacts:
refactor_plan.mdrefactor_plan.json
Use the detailed contract in
references/output-contract.md.
Stop Boundary
This skill must not:
- perform large unbounded rewrites
- make silent behavior changes
- skip invariant identification before proposing edits
- replace code review, test generation, CI, or human approval
- claim implementation completion when it only produced a plan
- create issues, PRs, commits, or release notes without explicit operator approval
- delete code without proof that the path is unused or replaced
Handoff candidates:
when characterization or regression tests are needed.test-generator
when the code surface needs defect review before planning.repo-code-review
when refactor output must be compared to an expected contract.gap-analysis
when human-approved follow-up issues are needed.finding-to-issue-planner
Blocked States
Return
not_run when the bounded target is missing.
Return
blocked when the request requires broad rewrite, silent behavior
change, repo mutation, or issue/PR creation without explicit approval.
Return
partial when the plan can be produced but the evidence is incomplete or
important invariants are unknown.