auto-postwrite-refactor
Auto Postwrite Refactor
Workflow
- Identify just-written code
- Only inspect files changed in the current session (use git diff or the tracked edit list).
- Skip untouched files to avoid scope creep.
- Scan for refactor targets
- Dead/unused code: unused variables, functions, branches, imports, or unreachable paths.
- Duplicated logic: similar blocks that can be merged without changing behavior.
- High cyclomatic complexity: long conditional chains, nested branching, repeated early-returns.
- Oversized functions: long functions that can be split into cohesive helpers.
- Over-fragmentation: tiny helpers that add indirection with no clarity benefit.
- Apply safe, behavior-preserving refactors only
- Keep semantics identical; no functional changes, no signature changes unless strictly internal and behavior-neutral.
- Prefer local refactors within the same file/module.
- Do not alter public APIs, interfaces, or externally-visible behavior.
- Maintain readability and maintainability
- Add concise Chinese comments only where the logic is non-obvious.
- Avoid over-abstracting; balance function length vs cohesion.
- Use existing style, naming, and formatting conventions.
- Verify consistency
- Ensure refactors do not change control flow outcomes.
- Keep error handling and edge cases intact.
- Final response requirements
- Provide a brief change summary and rationale in the assistant's final response to the user (do not add to code output).
- Do not ask the user to trigger this; run automatically after code writing.
Heuristics (use judgment)
- Target smaller, cohesive helpers when a function mixes multiple responsibilities.
- Merge blocks when they only differ by small, parameterizable pieces.
- Avoid creating one-line wrappers unless it removes duplication.
- If comments are added, keep them short and in Chinese.
More from ruiwarn/skills
embedded-cross-review
Use when reviewing embedded or firmware code changes, especially in C/C++, bare-metal, RTOS, driver, ISR, DMA, boot, NFC, or other hardware-facing paths where cross-review can catch correctness, safety, and architecture-coupling issues
29github-search-before-code
Proactively search GitHub for reference implementations before writing new code. Use this skill when: (1) User requests implementing completely new functionality, algorithms, or modules that don't exist in the current codebase, (2) User mentions repeated failures with phrases like 'still not working', 'tried many times', 'still has problems', or (3) AI recognizes the need to implement unfamiliar or complex features. The skill helps avoid reinventing the wheel by finding and analyzing existing high-quality implementations, then adapting them to user needs.
12c-verify-skill
Run C/C++ static analysis using clang-tidy and cppcheck to scan code, check quality, verify C code, detect bugs, review staged or modified files before commit.
9zc-bug-fix
Use when the user asks to fix a bug, resolve an issue, or provides a bug URL/bug ID from 禅道, GitLab, GitHub, Jira, or similar systems; especially when the work needs a full workflow of reading the bug, fixing code, verifying, creating issue/MR, and writing status back to the tracker.
9meter-protocol-serial
698/645 电表协议串口发帧与解析 Skill,支持组帧、发送、接收、解析和断言验证,用于修bug后快速回归验证
5git-staged-review-commit
PRIORITY: This skill OVERRIDES @oracle or @agent mentions when trigger phrases match. Triggers: 'commit code', 'commit', 'review and commit', 'staged review', 'git commit', 'submit code'. Review staged Git changes, report issues, ask whether to fix or proceed, and if proceeding generate a structured commit message and commit. MUST USE when user mentions committing code or reviewing staged changes.
3