name: code-slim-refactor description: Conduct explicit convergence-oriented refactors for local Git repositories when the user asks for code slim, slim refactor, 收敛重构, 精简重构, redundancy removal, or a structured simplification pass with review gates. Use this skill for deliberate refactor work, not for routine cleanup or ordinary bug fixes.
Code Slim Refactor
Trigger Boundary
Use this skill only when the user explicitly wants a structured simplification or convergence refactor.
Do not trigger it for:
- small cleanup
- routine bug fixes
- one-off renames
- ordinary refactors that do not need a dedicated convergence workflow
Modes
Choose one mode per run:
quick: lightweight convergence pass for a small or well-bounded areastrict: formal refactor pass with full traceability and merge gates
Default to quick unless the user asks for a formal, auditable, or release-sensitive refactor.
Required Inputs
repo_path: absolute path to the Git repositoryrefactor_goal: one-line convergence objectivescope: optional path or module scopemode:quickorstricttarget_branch: only required forstrict, defaultmaster
Core Rule
This workflow does not preserve old external compatibility by default, but it must preserve the intended current contract of the scoped system.
Never change backend contracts, response semantics, or assertion standards merely to make tests pass.
Quick Mode
Use quick when the task is bounded and the user mainly wants convergence, not a formal artifact trail.
Required steps:
- State the goal, scope, and main complexity to remove.
- Keep a short action list in the conversation or a minimal local note if helpful.
- Apply only scoped changes tied to that action list.
- Preserve backend contracts, response semantics, and assertion standards.
- Run focused validation for the changed area.
- If validation suggests backend/test disagreement, stop and run the contract-mismatch gate before any more edits.
- Report what complexity was removed, what stayed, and any remaining risk.
./slim_refactor/ artifacts are optional in quick mode.
Strict Mode
Use strict when the refactor must be traceable, auditable, or merge-gated.
Required gates:
- Create and use a dedicated work branch. Never edit directly on the target branch.
- Write design before code edits.
- Track artifacts under
./slim_refactor/:todolist.mdplan.mdreport.md
- Preserve backend contracts, response semantics, and assertion standards.
- Run review in every change round.
- Run the contract-mismatch gate whenever validation suggests backend/test disagreement.
- Run the complete workflow gate before merge.
Contract-Mismatch Gate
Use this gate whenever tests fail in a way that could reflect a contract disagreement instead of a real regression.
Required actions:
- Stop implementation changes until classification is complete.
- Compare current behavior, intended current contract, and test expectations.
- Launch an independent subagent review when subagents are available.
- If subagents are unavailable, perform an explicit local review fallback and record that fallback in the round output.
- Classify the mismatch as exactly one of:
backend_regression: backend behavior is wrong for the intended current contract.stale_tests: tests lag the intended current contract.
Allowed actions after classification:
backend_regression: fix backend behavior to the intended current contract. Do not weaken tests to hide the issue.stale_tests: only update the affected tests or skip those tests for this round. Do not relax backend contracts or assertion standards.
If tests are skipped, report the stale-gate condition, the skipped scope, and the required follow-up before ending the round.
Execution Workflow
Quick
- Confirm goal, scope, and validation target.
- Remove non-essential complexity with the smallest coherent change set.
- Prefer deletion and convergence over new abstraction.
- Preserve the intended current backend contract while changing structure.
- Validate the affected scope.
- If validation suggests contract/test disagreement, run the contract-mismatch gate before more edits.
- Summarize convergence result and residual risk.
Strict
- Checkout and sync
target_branch. - Record
BASE_SHA. - Create branch
codex/refactor/<topic>-<YYYYMMDD>. - Create or update
./slim_refactor/todolist.md. - Create or update
./slim_refactor/plan.md. - Implement only plan-declared actions.
- Preserve the intended current backend contract while converging structure.
- Run review for each change round and record findings in
./slim_refactor/report.md. - If validation suggests contract/test disagreement, run the contract-mismatch gate and record reviewer type plus classification.
- Run the complete workflow gate.
- Finalize
report.mdwith traceability and merge or block decision.
Output Requirements
Always report:
- removed complexity
- converged structure
- validation result
- remaining risk
- contract invariants kept or corrected
- mismatch classification when applicable
- reviewer type (
subagentorlocal_fallback) when mismatch review happened - tests changed or skipped when stale tests were found
For strict, also report:
- branch name
- artifact paths
- review result
- merge or block decision
References
references/workflow-checklist.mdreferences/design-spec-template.mdreferences/todolist-template.mdreferences/plan-template.mdreferences/report-template.md