AGENT SKILL

refactor

Use when refactoring code while preserving behavior — checkpoint, extract, test, audit

使用场景代码审查
License 许可
Apache-2.0
最近更新
2026-10-11
Stars
★ 7
Forks
8

01 前言 Front Matter

name
refactor
arguments
[ { "name": "target", "required": true, "description": "File or module to refactor" }, { "name": "goal", "required": false, "description": "What the refactoring should achieve" } ]
description
Use when refactoring code while preserving behavior — checkpoint, extract, test, audit

03 SKILL.md 正文

Refactor Workflow

When to use

  • Restructuring code that violates the Constructor Pattern (file >200 LOC, function >30 LOC, multiple responsibilities, duplicated code).
  • Safe refactoring that must preserve existing behaviour — checkpoint, tests baseline, extract, verify.
  • When wave-audit or /dev-guard flags a structural issue that requires decomposition.

Step 1: Understand Current State

  • Read target file(s) completely
  • Identify existing tests for the target
  • Run existing tests — baseline must pass
  • Document current behavior (inputs → outputs)

Step 2: Plan Refactoring

  • Identify what violates Constructor Pattern:
    • File >200 lines → decompose
    • Function >30 lines → extract
    • Multiple responsibilities → split
    • Duplicated code → single source
    • Overlay/patches → root formula
  • List concrete changes BEFORE making them

Step 3: Checkpoint

  • checkpoint: before refactor $target

Step 4: Refactor (Incremental)

  • ONE structural change at a time
  • After each change: run tests
  • If test breaks → fix immediately or revert
  • Preserve all public interfaces unless explicitly changing them

Step 5: Audit

  • Check: does refactored code follow Constructor Pattern?
  • Check: no overlay, no dead code, no orphaned imports
  • Check: SSOT — no duplicated logic
  • Check: file sizes within limits

Step 6: Final Verification

  • Run full test suite — all pass
  • Diff review: no accidental behavior changes
  • No new dependencies added without reason

Step 7: Commit

  • refactor: <what was restructured and why>

04 同仓库更多 Skills

KeiSeiLab
KeiSeiLab/KeiSeiKit

wave-audit

3-wave parallel audit — Wave 1 discovery (4 agents), Wave 2 verification (4 agents), Wave 3 cross-optimization (1 synthesizer). Each wave runs agents in parallel. Combines security review, runtime analysis, quality check, and constructor pattern into one unified workflow with evidence grading and Go/No-Go verdict.

Skill与智能体开发
★ 7
KeiSeiLab
KeiSeiLab/KeiSeiKit

vm-provision

End-to-end VPS provisioning — select provider → plan → provision → harden → verify (ssh-check + firewall-diff hard-gate) → handoff. 6 phases, ≥6 AskUserQuestion calls, defensive-only. Stops if either verification primitive fails.

★ 7
KeiSeiLab
KeiSeiLab/KeiSeiKit

visual-explainer

Generate beautiful, self-contained HTML pages that visually explain systems, code changes, plans, and data. Use when the user asks for a diagram, architecture overview, diff review, plan review, project recap, comparison table, or any visual explanation of technical concepts. Also use proactively when you are about to render a complex ASCII table (4+ rows or 3+ columns) — present it as a styled HTML page instead.

数据分析师前端开发
★ 7
KeiSeiLab
KeiSeiLab/KeiSeiKit

video-gen

Use when generating video from frame sequences — FFmpeg extraction, WebP/AVIF conversion, sprite sheets, scroll-synced playback, video encoding/transcoding. Covers the full pipeline from video source to web-ready frame sequence or optimized video.

图像与多媒体
★ 7
KeiSeiLab
KeiSeiLab/KeiSeiKit

test-matrix

Use when a project needs testing BEYOND unit tests — fuzzing, property-based, load, E2E, or mutation. Five-phase hub-and-spoke pipeline composes the right mix per language × critical path × CI target, scaffolds configs + corpus + fixtures, wires CI jobs, and defines the crash/regression triage workflow. Pure-click: every decision except intake is an AskUserQuestion.

测试与质量
★ 7
KeiSeiLab
KeiSeiLab/KeiSeiKit

test-gen

Use when generating tests for untested code — happy path, edge cases, error handling

测试与质量
★ 7