Refactor Op
Thin entry point. The catalog substance and the checks are shared repo artifacts: the deterministic
checker tools/refactor_op.py and the spec .agents/guidance/REFACTOR_OP_GUIDELINES.md. Keep this
skill thin; do not duplicate the catalog here. refactor-op is complementary to SonarQube CPD
(which owns generic, whole-corpus duplication) — it surfaces operator-scoped semantic redundancy
Sonar cannot express.
Workflow
- assess —
python3 tools/refactor_op.py <Operator>(scope with--domain impl|api|xcut;--format jsonfor machine output). Read-only and deterministic. Interpret each finding by itsRED-*id in.agents/guidance/REFACTOR_OP_GUIDELINES.md. - apply (only if asked to fix) — apply the finding's named corrective action on the
implementation / binding only, reusing existing shared utilities. Never edit the
operator's tests or anything under
bench/, and never change public API/ABI. - verify — when the MR scope includes a refactor, run
python3 tools/refactor_op.py <Operator> --phase verify --base <ref>locally and require zeroGAP(frozen test surface, frozen bench surface, API/ABI, feature-matrix and coverage-matrix parity), then build + run the frozenOp<Operator>tests (bit-exact, VER-6) and re-run assess (redundancy gone, VER-7). The verify report ends with a deterministic refactor summary (LOC delta +RED-*resolved before→after) — report it as the outcome. If the MR also changes performance-sensitive implementation, provide benchmark evidence through the optimization workflow.
Inviolable: refactoring changes nothing observable — bit-exact output, identical feature set, frozen
tests and benchmarks, unchanged API/ABI; never weaken a test or fabricate a baseline to pass. There
is no standing refactor-parity CI job; invoke the local verify flow when the MR scope calls for it.
Prompt Handling
Requests like "reduce duplication in Flip", "/refactor-op BrightnessContrast", "unify the Tensor and
VarShape kernels for Resize", "is there dead code in OpStack?", or "verify my refactor is bit-exact"
trigger this skill. Use --domain to scope; use --phase verify to gate an applied refactor.