code-refinement-discipline

Guides behavior-preserving refactoring decisions with evidence-based scope and verification gates.

Updated Aug 15, 2025
One-click install
npx skills add https://github.com/yehezkieldio/topaz --skill code-refinement-discipline-yehezkieldio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-refinement-discipline
Source: https://github.com/yehezkieldio/topaz/tree/main/.agents/skills/code-refinement-discipline
Command: npx skills add https://github.com/yehezkieldio/topaz --skill code-refinement-discipline-yehezkieldio

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Refactoring often drifts into style churn, speculative rewrites, or behavior-breaking changes. This Skill provides a disciplined decision framework for determining which code changes are earned, how to execute them in coherent slices, and when to stop. ## Core Features & Use Cases - Earned-Change Filter: Distinguishes real maintenance, correctness, and cognitive costs from style-only churn, speculative abstractions, and compatibility shims. - Structured Refactor Loop: Maps entry boundaries, canonical data shapes, state owners, and verification gates before patching the smallest set of files per responsibility. - Risk-Matched Verification: Scales checks from package-local lint and typecheck to broader validation when touching shared schemas, public exports, authorization, or route contracts. - Use Case: When cleaning up a Next.js/tRPC feature module, use this Skill to consolidate duplicated validation rules at the true boundary, delete unsupported legacy branches, and run focused typecheck and tests without weakening type safety or domain rules. ## Quick Start Use the code-refinement-discipline skill to run a behavior-preserving refactor pass on this module with clear scope, evidence, and verification.

Frequently Asked Questions about code-refinement-discipline

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I decide whether a refactor is worth doing?

A refactor is earned when the current shape creates real maintenance, correctness, or cognitive cost, such as duplicated domain rules, defensive branches for impossible shapes, or weak types bypassing invariants. Length, unfamiliarity, or aesthetic unevenness alone do not justify changes.

How to run a behavior-preserving refactor pass safely?

Start by reading repo instructions, callers, schemas, and tests to identify the behavior that must be preserved. Then work in coherent slices, patch the smallest set of files per responsibility, and run the nearest meaningful checks after each change.

What code changes should be avoided during refactoring?

Avoid style-only churn, file moves for visual neatness, premature generic utilities, compatibility shims without a supported external contract, and speculative memoization or caching. Also avoid collapsing domain structure into simpler code that loses validation or readability.

When should I stop a refactoring pass?

Stop when remaining issues are unrelated, speculative, or cosmetic. Do not stop after the first obvious cleanup if the same boundary still has duplicated rules, unclear ownership, or broken verification.

How should verification scale with refactoring risk?

Run package-local format, lint, typecheck, and tests for contained changes. Broaden checks when touching shared schemas, public exports, authorization, persistence mapping, route contracts, or cross-feature UI, and verify rendered output for UI changes.

What should I do when a refactor causes a test or type failure?

Fix the root cause of the failure rather than papering over it. Do not add fallback behavior, weaker types, looser schemas, optional fields, catch-all errors, or ignored promises to make the failure disappear.