Install
openclaw skills install sipoon-architecture-review定期扫描代码库架构质量,识别循环依赖、死代码、过大模块和高圈复杂度,生成报告指导重构优先级。
openclaw skills install sipoon-architecture-review借鉴来源:improve-codebase-architecture + CodeGraphContext 死代码检测
定期对代码库做架构质量扫描,识别腐烂信号(泥球、反循环依赖、死代码、圈复杂度超标)。
核心理念:架构问题不会一夜发生,但会日积月累。定期扫描比一次性重构便宜10倍。
满足以下任一场景时激活:
检查项:
工具:
# 检查循环依赖
npm run list:deps 2>/dev/null || npx madge --circular src/
# 统计模块行数
Get-ChildItem -Recurse src/**/*.ts | Get-Content | Measure-Object -Line
检查项:
工具:
# TypeScript/JavaScript
npx ts-prune 2>/dev/null || npx madge --not --extensions ts,tsx
# Python
vulture . --min-confidence 80
# Go
staticcheck ./... 2>/dev/null | grep "is never used"
# 通用(基于 tree-sitter 调用图)
# codegraph-index skill 已构建调用图,孤立的叶子节点 = 潜在死代码
检查项:
工具:
# TypeScript/JavaScript
npx complexity-report --dest ./complexity-report.html 2>/dev/null
# Python
radon cc -a -s src/
# 通用(Python 脚本)
python3 -c "
import os, ast
def cyclomatic(func_def):
score = 1
for node in ast.walk(func_def):
if isinstance(node, (ast.If, ast.While, ast.For, ast.ExceptHandler)):
score += 1
elif isinstance(node, ast.BoolOp):
score += len(node.values) - 1
return score
# 输出复杂度超标的函数
"
检查项:
工具:
# 检查全局状态滥用
grep -r "global\." src/ --include="*.ts" | head -20
grep -r "window\." src/ --include="*.ts" | head -20
检查项:
工具:
# 依赖检查
npm outdated 2>/dev/null
npx npm-check-updates 2>/dev/null
## 架构审查报告
### 模块结构
| 问题 | 位置 | 严重度 |
|------|------|--------|
| 循环依赖 A→B→C→A | src/a/, src/b/ | 🔴 高 |
| God Module | src/core.js (3500行) | 🟡 中 |
### 死代码
| 函数/变量 | 位置 | 建议 |
|-----------|------|------|
| unusedFunc | lib/utils.ts:42 | 删除 |
| oldAPI | api/routes.js:15 | 移除端点 |
### 圈复杂度超标
| 函数 | 位置 | 复杂度 | 建议 |
|------|------|--------|------|
| processPayment | services/pay.ts:88 | 18 | 拆分为3个函数 |
### 技术债务
| 类型 | 描述 | 建议 |
|------|------|------|
| 过期依赖 | lodash@3.2.0 | 升级到 4.x |
| 废弃 API | /api/v1/legacy | 移除或迁移 |
### 优先级排序
1. [立即处理] 循环依赖(影响所有新功能开发)
2. [本周处理] God Module 重构
3. [本月处理] 死代码清理
4. [下季度] 依赖升级
codegraph-index:先做索引,再查调用图和符号关系refactoring:发现架构问题后,用 refactoring skill 执行重构skill-compounding:如果某类架构问题反复出现,提取为检查清单 Skillarchitecture-review 是架构质量审查技能,审查完成后按以下路径调用:
refactoring 做重构agent-teams"审计一下这个项目"、"看看代码有没有问题"、"做一次架构审查"、"检查死代码"