Best for
- Use when the user says 'refactor this', 'clean this up', 'untangle this module', 'move this to the right layer', 'simplify this code', or 'improve this structure'.
techygarg/lattice/skills/molecules/refactor-safely/SKILL.md
Restructure existing code safely without changing externally observable behavior. Composes context, design, architecture, code quality, and testing guardrails into a characterization-first refactoring workflow. Use when the user says 'refactor this', 'clean this up', 'untangle this module', 'move this to the right layer', 'simplify this code', or 'improve this structure'.
Decision brief
Restructure existing code safely without changing externally observable behavior. Composes context, design, architecture, code quality, and testing guardrails into a characterization-first refactoring workflow.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/techygarg/lattice --skill "skills/molecules/refactor-safely"Inspect the Agent Skill "refactor-safely" from https://github.com/techygarg/lattice/blob/75b7e0728587f2e822e8cdbe11583a6f9a38a4b3/skills/molecules/refactor-safely/SKILL.md at commit 75b7e0728587f2e822e8cdbe11583a6f9a38a4b3. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
Start from current pain, not preferred abstraction.
Start from current pain, not preferred abstraction.
Refactoring changes structure, not behavior. Make preservation contract explicit before proposing structural edits.
Zero Refactor Rule: no structural code changes until user approves target structure and transition plan.
Before changing structure, lock current behavior with tests.
Permission review
No configured static risk pattern was detected
This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.
Evidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 86/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 170 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Load these skills based on refactor scope (see Steps 3, 5, 6 for conditional use):
framework:knowledge-priming -- Load project context (always)framework:context-anchoring -- Load/capture context doc (always)framework:learning-harvest -- Load prior learnings; harvest at session end (always)framework:collaborative-judgment -- Surface trade-offs in structure, seams, migration sequence (always)framework:clean-code -- Readability, responsibility boundaries, local craft (always)framework:test-quality -- Characterization tests and safety net (always)framework:design-first -- Significant structural changes (conditional)framework:architecture -- Layer placement and dependency direction (conditional)framework:domain-driven-design -- Aggregate boundaries and domain behavior (conditional)framework:secure-coding -- Security-sensitive code (conditional)Start from current pain, not preferred abstraction.
framework:learning-harvest Load behavior. Focus hint: "refactoring session — focus: structural health, quality signals".framework:context-anchoring Document Discovery to check for existing context doc for affected feature/module
End step, summarize intent one sentence:
"Refactor X to improve Y while preserving Z."
STOP: If can't state improvement target and preservation target that clearly, continue clarifying before planning changes.
Optional persistence check:
framework:context-anchoring, then use as source of truth for approved planRefactoring changes structure, not behavior. Make preservation contract explicit before proposing structural edits.
List behaviors that must remain unchanged:
Also list explicit out-of-scope changes:
This step defines refactor's safety boundary. If desired outcome requires changing preserved behavior, stop and discuss whether task actually bug fix, feature, or broader redesign.
Zero Refactor Rule: no structural code changes until user approves target structure and transition plan.
For small refactors, plan may be brief. For larger ones, use framework:design-first selectively:
Present:
End step with explicit gate:
"Does this refactor plan look correct? Should I proceed to Step 4: characterization tests?"
STOP: Don't write refactor code until user explicitly approves.
If persistence enabled, use framework:context-anchoring Enrich behavior to capture approved preservation boundaries, target structure, movement plan, out-of-scope items. STOP: Don't proceed to Step 4 until plan written.
Before changing structure, lock current behavior with tests.
framework:test-quality inlineStopping rule:
End step with explicit gate:
"Characterization tests in place and passing. Ready to discuss refactor strategy and pacing?"
STOP: Don't proceed to strategy selection until safety net verified green.
After user approves high-level plan and safety net in place, choose implementation approach.
Preferred strategies:
framework:architecturePreferred pacing:
"How would you like review refactor?"
- Slice-by-slice (recommended) -- Refactor one safe slice at time, pause after each slice. Best for risky legacy code.
- Layer-by-layer -- Complete refactor for one structural layer or concern, then pause for review. Best for broader architectural cleanup.
- Full autonomy -- Execute approved refactor end-to-end, present complete result at end. Best for tightly scoped, low-risk refactors. (Still pause if slice reveals approved plan unsafe or invalid — see Step 6 Deviation Rule.)
Default to slice-by-slice if user doesn't express preference.
Implement only within approved preservation boundaries and target structure.
For each slice:
framework:collaborative-judgment, surface them before presenting slice's code. Don't interrupt mid-slice unless approved plan becomes unsafe or invalid.Always apply:
framework:clean-code -- better boundaries, simpler control flow, smaller focused units, clearer namingframework:test-quality -- maintain strong characterization tests and nearby supporting testsConditionally apply:
framework:architectureframework:domain-driven-designframework:secure-codingDeviation rule:
Refactor succeeds only if both true:
Verify preservation:
Verify structural improvement:
When reporting completion, be explicit about both:
Use framework:context-anchoring Enrich behavior to preserve important parts of refactor:
If no context doc exists and refactor involved non-trivial structural reasoning, suggest creating one so decisions not lost across sessions.
Harvest learnings. Use framework:learning-harvest Harvest behavior. Session context: "refactoring session — structural restructuring and debt resolution". Synthesize and propose cross-cutting patterns from this session — structural debt that accumulated, migration strategies that worked, characterization test gaps discovered. User confirms what enters the document. STOP: run this before recommending /review below.
After refactor complete, recommend /review when change:
Alternatives
AI-Unified-Process/marketplace
Creates Vaadin Browserless server-side unit tests for Vaadin views covering navigation, component interactions, form validation, grid operations, and notifications. Use when the user asks to "write Browserless tests", "write Vaadin UI unit tests", "unit test a Vaadin view without a browser", "create view tests with the official Vaadin testing framework", or mentions Browserless testing, SpringBrowserlessTest, browserless-test-junit6, UI Unit Testing, or server-side Vaadin testing.
mgiovani/cc-arsenal
Multi-agent review team: architecture, security, performance, testing, style, docs/UX, plus an adversary that cross-examines the other 6, for security-sensitive, architectural, or large PRs (15+ files) where a single-agent pass risks missing cross-cutting issues. Use for auth/payments/PII changes, schema/pattern changes, compliance sign-off, or when asked to 'get the review team on this' / 'multi-agent review' / 'thorough review before merge'. For a standard PR or a quick pre-merge check, use /r
event4u-app/agent-config
Use when writing Playwright E2E tests — browser automation, visual regression testing, Page Objects, fixtures, and reliable test patterns.
JasonColapietro/suede-creator-skills
Design AI evals that catch regressions before users do: rubrics, test cases, failure modes, acceptance gates, and AI-SPEC artifacts.