In the DSH ecosystem, code reviews usually focus on PR diffs, while architecture documentation focuses on overall structure. The dsh-refactor-insight plugin fills this gap: it scans the entire codebase to identify code smells and outputs a prioritized, actionable refactoring plan.

This is a DSH skill plugin maintained by duyanta123. It addresses the lack of a structured, prioritized refactoring plan for identifying technical debt such as oversized files, deeply nested structures, and coupled modules.

Core Features

The plugin includes six deterministic rules (zero-dependency heuristics) for detecting code smells:

  • Oversized files: The default threshold is more than 400 lines.
  • Long functions: Depending on language support, detects Python indentation blocks / JS-TS braces / Go function declarations; a function body exceeding 80 lines.
  • Deep nesting: The maximum indentation or brace depth exceeds 5 by default.
  • God object: A class has more than 10 methods, or the class body exceeds 300 lines (Go detects the number of receiver methods).
  • Highly coupled modules: Uses arch-profile --deps output to analyze hub modules by in-degree/out-degree and detects dependency cycles with Tarjan’s algorithm.
  • TODO/FIXME density: A noise metric per 1,000 lines of code.

Installation and Enablement

Install it as a DSH plugin:

dsh plugin --profile web add "github:duyanta123/dsh-refactor-insight#v0.1.3"

After installation, restart the corresponding profile.

Typical Usage

1. Use It as a DSH Skill

After installing and restarting the profile, instruct the agent:

Use refactor-insight to health-check /path/to/repo

The agent will run a four-stage runbook (ingest → scan → diagnose → priority orchestration) and generate REFACTOR-PLAN.md.

2. Run Only the Diagnostics CLI

The diagnostic scripts are zero-dependency and can run without a DSH environment:

# Run all six rules
node scripts/refactor-smell.mjs <repo_path>

# Combine arch-profile dependency output for coupling/cycle detection
node scripts/arch-profile.mjs <repo_path> --deps > deps.json
node scripts/refactor-smell.mjs <repo_path> --deps-json deps.json

Notes

  • Plan generation only: The plugin outputs a plan rather than a diff and does not automatically generate code changes. High-risk refactoring items require manual confirmation.
  • Read-only scanning: The diagnostic scripts have no dependencies, no child processes, and no network requests, and they do not modify the source code of the target repository.
  • Facts versus inferences: The scripts output hard facts (such as file line counts); severity, cost, and recommendations are added by the LLM after denoising and are inferential information.
  • Noise metric: The TODO/FIXME density rule is only a noise metric (counted per 1,000 lines) and does not require action.

Ecosystem Context

The DSH philosophy is “everything is a plugin.” This plugin belongs to the workflow category and is licensed under MIT. See the SkillHub catalog or the GitHub repository for more details.