AgentSkillsCN

uncomplex-analyzer

寻找复杂代码,分析其意图,并推荐久经考验的替代库。借助radon/eslint进行检测,通过GitHub质量搜索寻找可行的替代方案。

SKILL.md
--- frontmatter
name: uncomplex-analyzer
description: Find complex code, analyze intent, recommend battle-tested library replacements. Uses radon/eslint for detection, GitHub quality search for alternatives.

Uncomplex Analyzer

Detect complexity → understand intent → replace with libraries or simplify.

Quick Run

bash
# Python
radon cc <file_or_dir> -s --min C

# JS/TS
bunx eslint <file_or_dir> --rule 'complexity: [error, 15]' --format json

Workflow

1. Detect (tools do the work)

Cyclomatic complexity:

bash
# Python — install once: pip install radon
radon cc <directory> -s -j --min C | jq '.'
radon hal <file>   # Halstead: effort > 500 = hard to read

# JS/TS
bunx eslint <directory> --rule 'complexity: [error, 15]' --format json

Circular dependencies:

bash
# Python — install once: pip install pydeps
pydeps <directory> --no-output --show-cycles

# JS/TS
bunx madge --circular <directory>

Duplication:

bash
bunx jscpd . --threshold 5 --reporters console --ignore "**/*.json,**/*.md,**/*.lock,**/node_modules/**"

Thresholds: CC 15+ = review. CC 20+ = strong replacement candidate. CC 25+ = split or replace.

2. Analyze Intent

For each complex function, answer: what is this trying to accomplish? (not how)

Then check if someone already solved it:

Code PatternIntentPythonJS/TS
Manual base64 + HMACJWT authpyjwtjose
Nested retry loopsRetry with backofftenacityp-retry
Date string parsingDate manipulationpendulumdayjs
Deep object mergingObject utilitiesdeepmergelodash/merge
Manual HTML parsingWeb scrapingbeautifulsoup4cheerio
Regex-heavy validationSchema validationpydanticzod
Hand-rolled state machineFSM / workflowtransitionsxstate
Manual CSV/Excel parsingTabular datapandaspapaparse
Custom caching logicCache with TTL/LRUcachetoolslru-cache
Manual rate limitingRate limiterratelimitbottleneck
Hand-rolled queueTask queuecelery, rqbull
Custom logging formatStructured loggingstructlogpino
Subprocess orchestrationTask runnerinvokeexeca

If the pattern isn't in this table, search:

bash
~/.pi/agent/skills/github-quality-search/github_search.py \
  "<intent keywords>" -l <language> -s 100 -n 3 --json

Quality gates: 100+ stars, MIT/Apache/BSD, commit in last 6 months, has docs.

3. Decide: Replace or Refactor?

Replace when the problem is generic (dates, HTTP, validation, parsing) and a quality library exists.

Refactor when logic is domain-specific or a library would be overkill. Keep it simple:

  • God function → split into named helpers
  • Deep nesting → guard clauses + early returns
  • Copy-paste → extract shared function
  • 5+ params → config object

Leave alone when:

  • Low churn (stable, not causing bugs)
  • Domain complexity (the problem IS complex)
  • Intentional — comments explain why, perf-critical path, no-dependency policy

4. Report

Create uncomplex-report-YYYYMMDD.md with:

  • Summary stats (files scanned, high-complexity count)
  • Each finding: location, complexity score, intent, recommendation (library or refactoring)
  • Library replacements table (name, stars, license, migration effort)
  • Top 3 priorities

Cross-References

  • Prioritize targets: hotspot-detective (high churn + high complexity = act first)
  • Clean up after: dead-code-reaper
  • Library discovery: github-quality-search

Combo: hotspot-detectiveuncomplex-analyzerdead-code-reaper

Dependencies

bash
pip install radon pydeps          # Python
# JS/TS: bunx eslint, bunx jscpd, bunx madge (zero-install)