npx skills add https://github.com/boshu2/agentops --skill complexity你必须执行此工作流程。不要仅仅描述它。
分析代码复杂度以识别重构目标。
给定 /complexity [路径]:
如果提供了路径: 直接使用它。
如果未提供路径: 使用当前目录或最近的更改:
git diff --name-only HEAD~5 2>/dev/null | grep -E '\.(py|go)$' | head -10
# 检查 Python 文件
ls *.py **/*.py 2>/dev/null | head -1 && echo "检测到 Python"
# 检查 Go 文件
ls *.go **/*.go 2>/dev/null | head -1 && echo "检测到 Go"
对于 Python(使用 radon):
# 检查 radon 是否已安装
which radon || pip install radon
# 运行圈复杂度分析
radon cc <路径> -a -s
# 运行可维护性指数分析
radon mi <路径> -s
对于 Go(使用 gocyclo):
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 检查 gocyclo 是否已安装
which gocyclo || go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
# 运行复杂度分析
gocyclo -over 10 <路径>
圈复杂度等级:
| 等级 | CC 分数 | 含义 |
|---|---|---|
| A | 1-5 | 低风险,简单 |
| B | 6-10 | 中等,可管理 |
| C | 11-20 | 高风险,复杂 |
| D | 21-30 | 极高风险 |
| F | 31+ | 不可测试,立即重构 |
列出需要关注的函数/方法:
写入: .agents/complexity/YYYY-MM-DD-<目标>.md
# 复杂度报告:<目标>
**日期:** YYYY-MM-DD
**语言:** <Python/Go>
**已分析文件:** <数量>
## 摘要
- 平均 CC:<分数>
- 最高 CC:<分数>(位于 <函数>)
- 超过阈值的函数:<数量>
## 重构目标
### 严重(CC > 20)
| 函数 | 文件 | CC | 建议 |
|----------|------|-----|----------------|
| <名称> | <文件:行号> | <分数> | <如何简化> |
### 高(CC 11-20)
| 函数 | 文件 | CC | 建议 |
|----------|------|-----|----------------|
| <名称> | <文件:行号> | <分数> | <如何简化> |
## 重构建议
1. **<函数>**:<具体建议>
- 提取:<提取什么>
- 简化:<如何简化>
## 后续步骤
- [ ] 首先处理严重复杂度
- [ ] 为高复杂度创建问题
- [ ] 考虑进行重构冲刺
告知用户:
简化高复杂度:
用户说: /complexity src/
会发生什么:
src/ 目录中的 Python 文件radon cc src/ -a -s 进行圈复杂度分析radon mi src/ -s 进行可维护性指数分析.agents/complexity/2026-02-13-src.mdprocess_request() 函数中的嵌套条件语句结果: 复杂度报告将 process_request()(CC:28)识别为关键重构目标,并提供了具体的提取建议。
用户说: /complexity
会发生什么:
git diff --name-only HEAD~5 检查最近的更改gocyclo -over 10 ./...HandleWebhook() 函数复杂度为 34结果: 识别出需要立即重构的关键函数,并提供了可操作的提取计划。
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 工具未安装(radon/gocyclo) | 缺少依赖项 | 代理自动安装:Python 用 pip install radon,Go 用 go install github.com/fzipp/gocyclo/cmd/gocyclo@latest。验证 $PATH 中的安装路径。 |
| 未发现复杂度问题 | 阈值太高或代码确实简单 | 降低阈值:尝试 gocyclo -over 5 或检查路径是否包含实际实现文件而非测试文件。 |
| 报告显示函数无建议 | 通用分析,缺乏代码库上下文 | 阅读高 CC 函数以理解结构,然后根据实际代码模式提供具体的重构建议。 |
| 混合语言项目 | 目标路径中包含多种语言 | 按语言分别运行分析:先 /complexity src/python/,然后 /complexity src/go/,手动合并报告。 |
每周安装次数
219
仓库
GitHub 星标数
197
首次出现
2026年2月2日
安全审计
安装于
opencode216
codex214
github-copilot212
gemini-cli212
amp210
kimi-cli210
YOU MUST EXECUTE THIS WORKFLOW. Do not just describe it.
Analyze code complexity to identify refactoring targets.
Given /complexity [path]:
If path provided: Use it directly.
If no path: Use current directory or recent changes:
git diff --name-only HEAD~5 2>/dev/null | grep -E '\.(py|go)$' | head -10
# Check for Python files
ls *.py **/*.py 2>/dev/null | head -1 && echo "Python detected"
# Check for Go files
ls *.go **/*.go 2>/dev/null | head -1 && echo "Go detected"
For Python (using radon):
# Check if radon is installed
which radon || pip install radon
# Run cyclomatic complexity
radon cc <path> -a -s
# Run maintainability index
radon mi <path> -s
For Go (using gocyclo):
# Check if gocyclo is installed
which gocyclo || go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
# Run complexity analysis
gocyclo -over 10 <path>
Cyclomatic Complexity Grades:
| Grade | CC Score | Meaning |
|---|---|---|
| A | 1-5 | Low risk, simple |
| B | 6-10 | Moderate, manageable |
| C | 11-20 | High risk, complex |
| D | 21-30 | Very high risk |
| F | 31+ | Untestable, refactor now |
List functions/methods that need attention:
Write to: .agents/complexity/YYYY-MM-DD-<target>.md
# Complexity Report: <Target>
**Date:** YYYY-MM-DD
**Language:** <Python/Go>
**Files Analyzed:** <count>
## Summary
- Average CC: <score>
- Highest CC: <score> in <function>
- Functions over threshold: <count>
## Refactor Targets
### Critical (CC > 20)
| Function | File | CC | Recommendation |
|----------|------|-----|----------------|
| <name> | <file:line> | <score> | <how to simplify> |
### High (CC 11-20)
| Function | File | CC | Recommendation |
|----------|------|-----|----------------|
| <name> | <file:line> | <score> | <how to simplify> |
## Refactoring Recommendations
1. **<Function>**: <specific suggestion>
- Extract: <what to extract>
- Simplify: <how to simplify>
## Next Steps
- [ ] Address critical complexity first
- [ ] Create issues for high complexity
- [ ] Consider refactoring sprint
Tell the user:
Simplifying High Complexity:
User says: /complexity src/
What happens:
src/ directoryradon cc src/ -a -s for cyclomatic complexityradon mi src/ -s for maintainability index.agents/complexity/2026-02-13-src.mdprocess_request() functionResult: Complexity report identifies process_request() (CC: 28) as critical refactor target with specific extraction recommendations.
User says: /complexity
What happens:
git diff --name-only HEAD~5gocyclo -over 10 ./... on projectHandleWebhook() function with complexity 34Result: Critical function identified for immediate refactoring with actionable extraction plan.
| Problem | Cause | Solution |
|---|---|---|
| Tool not installed (radon/gocyclo) | Missing dependency | Agent auto-installs: pip install radon for Python or go install github.com/fzipp/gocyclo/cmd/gocyclo@latest for Go. Verify install path in $PATH. |
| No complexity issues found | Threshold too high or genuinely simple code | Lower threshold: try gocyclo -over 5 or check if path includes actual implementation files vs tests. |
| Report shows functions without recommendations | Generic analysis without codebase context | Read the high-CC functions to understand structure, then provide specific refactoring suggestions based on actual code patterns. |
| Mixed language project | Multiple languages in target path | Run analysis separately per language: /complexity src/python/ then , combine reports manually. |
Weekly Installs
219
Repository
GitHub Stars
197
First Seen
Feb 2, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode216
codex214
github-copilot212
gemini-cli212
amp210
kimi-cli210
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
102,600 周安装
/complexity src/go/