home / skills / zpankz / mcp-skillset / code-refactoring2

code-refactoring2 skill

/code-refactoring2

This skill helps you refactor Go hotspots using a BAIME-aligned protocol with automated metrics, tests, and documentation generation.

npx playbooks add skill zpankz/mcp-skillset --skill code-refactoring2

Review the files below or copy the command above to add this skill to your agents.

Files (30)
SKILL.md
1.2 KB
---
name: Code Refactoring
description: BAIME-aligned refactoring protocol for Go hotspots (CLIs, services, MCP tooling) with automated metrics (e.g., metrics-cli, metrics-mcp) and documentation.
allowed-tools: Read, Write, Edit, Bash, Grep, Glob
---

λ(target_pkg, target_hotspot, metrics_target) → (refactor_plan, metrics_snapshot, validation_report) |
  ∧ configs = read_json(experiment-config.json)?
  ∧ catalogue = configs.metrics_targets ∨ []
  ∧ require(cyclomatic(target_hotspot) > 8)
  ∧ require(catalogue = [] ∨ metrics_target ∈ catalogue)
  ∧ require(run("make " + metrics_target))
  ∧ baseline = results.md ∧ iterations/
  ∧ apply(pattern_set = reference/patterns.md)
  ∧ use(templates/{iteration-template.md,refactoring-safety-checklist.md,tdd-refactoring-workflow.md,incremental-commit-protocol.md})
  ∧ automate(metrics_snapshot) via scripts/{capture-*-metrics.sh,count-artifacts.sh}
  ∧ document(knowledge) → knowledge/{patterns,principles,best-practices}
  ∧ ensure(complexity_delta(target_hotspot) ≥ 0.30 ∧ cyclomatic(target_hotspot) ≤ 10)
  ∧ ensure(coverage_delta(target_pkg) ≥ 0.01 ∨ coverage(target_pkg) ≥ 0.70)
  ∧ validation_report = validate-skill.sh → {inventory.json, V_instance ≥ 0.85}

Overview

This skill defines a BAIME-aligned refactoring protocol focused on Go hotspots such as CLIs, services, and MCP tooling. It produces a concrete refactor plan, automated metric snapshots, and a validation report to ensure safety and measurable improvement. The workflow emphasizes incremental commits, test-driven refactoring, and automated capture of complexity and coverage metrics.

How this skill works

The skill inspects a target package and hotspot, requiring a high cyclomatic complexity (typically >8) and an allowed metrics target from the experiment configuration. It runs the configured metrics target, captures baseline results, applies reference patterns and templates, and automates metric snapshots via scripts. The process enforces measurable goals (complexity reduction, minimal coverage deltas) and produces an inventory and validation artifacts with a minimum validation score.

When to use it

  • Refactoring Go CLI commands, microservices, or MCP tooling with high cyclomatic complexity
  • When you need measurable, automated evidence of refactor impact (complexity and coverage)
  • For teams requiring a safe, incremental, TDD-oriented refactor protocol
  • Before release if code complexity threatens maintainability or automation metrics are mandated
  • When you want standardized documentation of patterns, principles, and best practices

Best practices

  • Start by capturing a baseline metrics snapshot and preserving iteration artifacts
  • Require a safety checklist and TDD workflow for each refactor iteration
  • Apply approved pattern sets and use the provided templates for consistency
  • Enforce small, incremental commits and frequent metric automation runs
  • Target measurable goals: ≥30% complexity reduction or cyclomatic ≤10 and maintain coverage thresholds

Example use cases

  • Refactor a monolithic CLI command with cyclomatic >8 into smaller, testable units
  • Improve maintainability of an MCP tooling module while proving coverage and complexity gains
  • Standardize service refactors across a team using the same templates and safety checklist
  • Automate metric collection for a series of refactor iterations to include in release notes
  • Validate refactor outcomes with an inventory.json and a validation score for compliance gates

FAQ

What metrics are required to run this protocol?

A configured metrics target from experiment-config.json must run (e.g., metrics-cli or metrics-mcp). Baseline and iteration results are captured automatically.

What are the success criteria for a refactor?

Success requires measurable complexity improvement (≥30% reduction or cyclomatic ≤10) and either a coverage delta ≥1% or absolute coverage ≥70%, plus validation artifacts and a minimum validation score.