360 Secure SkillHub
360 安全技能中心

RedHat Code Refactor Engine

核心功能是在严格保留代码行为的前提下,优化代码的可读性、模块化与可维护性。适用于代码复杂度攀升、存在跨模块重复逻辑且有测试(或可新增测试)保障行为的场景。需输入目标重构区域、重构目标等信息,输出重构摘要、变更文件、行为测试及验证结果,通过分步小改+多次验证确保安全,避免大改或破坏公共API。

mzfshark
mzfshark
热度 36.89
最近更新 2026-05-11 17:45:41
分类:开发依赖:代码执行 / 读写文件 / 内部调用大模型应用场景:代码审查

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add axodus-refactor-engine
Metadata
name
refactor-engine
description
Refactor code safely without changing behavior.
metadata
{"author":"RedHat Dev","version":"1.0.0","owner":"RedHat Dev Agent","category":"core"}

SKILL: refactor-engine

Purpose

Improve existing code structure (readability, modularity, maintainability) while preserving behavior.

When to Use

  • Complexity is growing and changes are becoming risky.
  • Duplicate logic appears across modules.
  • Tests exist (or can be added) to protect behavior.

Inputs

  • target_area (required, string): file(s)/module(s) to refactor.
  • refactor_goal (required, string): what improves (e.g., reduce duplication, isolate side effects).
  • constraints (optional, string[]): behavior must not change; performance bounds; compatibility.
  • validation_commands (optional, string[]): tests/build/lint to run before/after.

Steps

  1. Establish a baseline:
    • run existing tests (or add a minimal characterization test)
  2. Identify refactor seam(s):
    • extract pure functions
    • isolate I/O
    • reduce global state
  3. Apply refactor in small commits/patches:
    • one transformation per step
    • keep diffs readable
  4. Re-run validations after each meaningful transformation.
  5. If behavior changes, revert that change and adjust approach.

Validation

  • Behavior is preserved (tests pass; outputs unchanged for known cases).
  • Public interfaces remain stable (or are versioned/migrated explicitly).
  • Complexity decreases measurably (smaller functions, fewer branches, less duplication).

Output

  • refactor_summary
  • files_changed
  • behavior_guards (tests added/used)
  • validation_results

Safety Rules

  • Do not refactor without a behavior guard (tests or a deterministic reproduction).
  • Avoid “big bang” rewrites.
  • Do not change public APIs unless explicitly required.

Example

Goal: “Extract request validation from controller into validators/ and add unit tests.” Validation: pnpm test after each extraction step.