Install
openclaw skills install code-to-requirement-analyser智能分析交易维度前端代码,自动逆向推导业务需求,构建可复用的交易知识图谱。支持 Vue/React/Angular 多技术栈,具备智能缓存和错误恢复机制。
openclaw skills install code-to-requirement-analyser智能分析交易维度前端代码,自动逆向推导业务需求,构建可复用的交易知识图谱。
# Vue 文件(使用缓存)
python3 scripts/cli.py parse ./src/views/Order.vue
# React 文件
python3 scripts/cli.py parse ./src/views/Order.tsx
# 强制重新解析(跳过缓存)
python3 scripts/cli.py parse ./src/views/Order.vue --no-cache
# 保存结果到文件
python3 scripts/cli.py parse ./src/views/Order.vue -o result.json
# 分析并生成报告
python3 scripts/cli.py full ./src/views/Order.vue --generate-report report.md
# 分析并保存到知识库
python3 scripts/cli.py full ./src/views/Order.vue --save-knowledge
# 禁用缓存的完整分析
python3 scripts/cli.py full ./src/views/Order.vue --no-cache --generate-report report.md
# 搜索知识库
python3 scripts/cli.py knowledge --search "基金"
# 查找关联知识
python3 scripts/cli.py knowledge --related KNOW-20240101-xxx
# 查看知识库概览
python3 scripts/cli.py knowledge
# 查看缓存统计
python3 scripts/cli.py cache --stats
# 清除所有缓存
python3 scripts/cli.py cache --clear
文件内容 → SHA256 哈希 → 缓存键
↓
检查缓存存在?
↓
是 → 返回缓存结果(7天有效期)
否 → 执行解析 → 保存到缓存 → 返回结果
~/.openclaw/cache/trade-analyzer/| 场景 | 建议 |
|---|---|
| 日常分析 | 使用缓存(默认) |
| CI/CD 流水线 | 使用缓存 |
| 代码变更后 | 首次分析后缓存自动更新 |
| 强制重新分析 | 使用 --no-cache 参数 |
{
"file_info": {
"path": "/path/to/file.vue",
"type": "vue",
"size": 3584,
"has_scoped_style": true
},
"structure": {
"template_lines": 45,
"script_lines": 120,
"imports": [...],
"components_used": [...]
},
"components": [
{
"name": "el-input",
"type": "input",
"props": {...},
"events": ["input", "blur"],
"business_semantic": "文本输入"
}
],
"apis": [
{
"method": "POST",
"endpoint": "/api/order/submit",
"params": {...},
"business_purpose": "创建资源"
}
],
"business_rules": [
{
"rule_type": "validation",
"expression": "required: true",
"confidence": 0.95,
"business_meaning": "必填校验"
}
],
"complexity": {
"lines_of_code": 165,
"cyclomatic_complexity": 12,
"component_count": 8,
"api_count": 3
}
}
{
"trade_dimension": {
"lifecycle": ["创建", "审核"],
"trade_type": ["申购"],
"product_type": ["基金"],
"channel": ["手机银行"],
"parties": ["客户"]
},
"functional_requirements": [
{
"id": "FR-001",
"name": "基金申购信息录入",
"priority": "P0",
"scenario": "客户需要申购基金时",
"acceptance_criteria": [...]
}
],
"business_rules": [...],
"data_dictionary": [...],
"business_process": {...},
"analysis_confidence": {
"overall": 0.85,
"dimension_confidence": 0.9,
"component_confidence": 0.8
},
"suggestions": [...]
}
| 场景 | 处理方式 |
|---|---|
| 文件编码错误 | 尝试多种编码,使用 replace 模式 |
| 正则表达式错误 | 记录警告,返回空结果 |
| 复杂嵌套结构 | 简化处理,提取部分信息 |
| 不支持的语法 | 记录警告,跳过该项 |
# 知识库存储根目录
KNOWLEDGE_BASE_PATH="~/.openclaw/knowledge/trade/"
# 解析缓存目录
CACHE_DIR="~/.openclaw/cache/trade-analyzer/"
# 用于深度语义分析的 LLM API
LLM_API_KEY="your-api-key"
# 基础依赖(必需)
pip install chardet
# 可选依赖(增强功能)
pip install openai # LLM 深度分析
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ CLI 入口 │────▶│ 解析器选择 │────▶│ VueParser │
└─────────────┘ └─────────────┘ ├─────────────┤
│ ReactParser │
├─────────────┤
│AngularParser│
└──────┬──────┘
↓
┌─────────────┐
│ CacheManager│
│ (文件指纹) │
└──────┬──────┘
↓
┌─────────────┐
│ TradeBusiness│
│ Analyzer │
└──────┬──────┘
↓
┌─────────────┐
│KnowledgeGraph│
│ Builder │
└─────────────┘
cache 命令from parser.base import BaseCodeParser, ParsedComponent, ParsedAPI, ParsedRule
class NewFrameworkParser(BaseCodeParser):
def parse(self) -> Dict[str, Any]:
# 实现解析逻辑
pass
def extract_components(self) -> List[ParsedComponent]:
# 提取组件
pass
def extract_apis(self) -> List[ParsedAPI]:
# 提取 API
pass
def extract_business_rules(self) -> List[ParsedRule]:
# 提取业务规则
pass
# config/taxonomy.yaml
lifecycle:
创建:
indicators: ["录入", "选择", "确认"]
审核:
indicators: ["初审", "复审", "终审"]
trade_types:
买入:
variants: ["认购", "申购", "定投"]
# 检查解析器状态
python3 -c "
import sys
sys.path.insert(0, 'scripts')
from parser.vue_parser import VueParser
from parser.react_parser import ReactParser
print('✓ VueParser 可用')
print('✓ ReactParser 可用')
"
# 检查缓存状态
python3 scripts/cli.py cache --stats
| 问题 | 解决方案 |
|---|---|
| 解析失败 | 检查文件编码,使用 --no-cache 重试 |
| 缓存不更新 | 使用 --no-cache 强制重新解析 |
| React 解析为空 | 确保文件后缀为 .jsx 或 .tsx |
| 知识库写入失败 | 检查 KNOWLEDGE_BASE_PATH 权限 |
MIT License
0xSteven
持续优化中,欢迎反馈和贡献。