Files

74 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
实现 Profile 健康分(P0-2)。评分引擎 + API + 前端页面。
## 第一部分: 健康分计算引擎
创建 backend/app/services/health_scorer.py:
评分规则(PRD §P0-2):
- Gateway 稳定性 40%: 7天在线率×40 + 日均重启≤0.3得满分
- 配置完整性 25%: 必填字段检查(.env+config.yaml),缺1个扣10%
- Skill 一致性 20%: 与基准 Skill 清单对比
- Cron 成功率 15%: 24h Cron 成功率×15
等级: A(80-100) B(60-79) C(40-59) D(0-39)
函数:
- calculate_health_score(profile_name: str) -> HealthScore
- calculate_all_scores() -> list[HealthScore]
- 数据来源: 读取 .env + config.yaml 文件, 调 hermes CLI 获取 Gateway/Cron 状态
- 暂用占位数据(TODO: connect to real data sources),但评分逻辑要完整实现
- 评分结果缓存到 score_results dict, 每天凌晨自动刷新
## 第二部分: Health API
创建 backend/app/api/health.py,全部 require_auth
### GET /api/v1/health/scores
返回全部 Profile 健康分排行列表
- query: ?grade=A|B|C|D&sort=asc|desc
- 默认: 从低到高(D 排最前)
- 每行: rank, name, total_score, grade, gateway_score, config_score, skill_score, cron_score, deduct_summary
### GET /api/v1/health/scores/{profile}
返回单 Profile 详情:
- 四维度得分/满分 + 具体扣分项列表 + 修复建议
### POST /api/v1/health/compare
body: {"profile_names": ["hebo", "ops-engineer"]}
返回对比表: 横向 Profile, 纵向配置/Skill 字段, ✅/❌/⚠
### POST /api/v1/health/calculate
手动触发全量评分计算 (需 owner)
## 第三部分: 前端 Health 页面
修改 frontend/src/pages/HealthPage.tsx:
### 顶部: 四级分布卡片
- 4 个 Card: A(绿) B(蓝) C(黄) D(红)
- 显示数量 + 等级标签
- 点击卡片筛选对应等级
### 筛选栏
- 等级筛选: 全部 A B C D
- 对比按钮: 选中≥2 个 Profile 后启用
- 排序切换: 默认问题优先(D→A)
### 评分列表
- Table 组件
- 列: 排名, Profile名, 总分(颜色编码), 等级 Badge, 四维度分, 主要扣分项, 操作
- 可展开行: 点击展开四维度扣分明细面板(内嵌展开,不跳转)
- D 级行标红
### 批量对比视图
- 勾选 2-20 个 Profile → "对比选中"按钮
- 对比表: 横向 Profile, 纵向字段, ✅有/❌无/⚠版本不同
- 差异行黄色背景高亮
- 支持"只看差异"切换
### 四态覆盖
注册路由: main.py 添加 health router。
完成后提交。