Files
MoFin/docs/self-healing-loop.md
T
知微 4407f35027 feat: 自愈循环系统 + xiaoguo信号桥
- 新增 docs/self-healing-loop.md: 自愈循环设计文档
- 修改 morning_health_check.py: 发现异常后自动写入TODO系统
  - severity=critical→priority=high, error→medium, warn→low
  - 相同问题已completed→重新打开并升一级
  - 已有pending→不重复
- 新增 scripts/xiaoguo_signal_consumer.py: 知微消费小果扫描信号
  - 每30分钟盘中运行
  - 读signal_news未处理xiaoguo信号
  - 五维快速评估→加自选/关注/跳过
  - 标记processed=1
- 新增 cron: 小果信号消费-盘中 (15,45 9-15)
- 更新health_checklist自维护机制

自愈循环: 体检→TODO→修复→验证
2026-06-24 20:14:53 +08:00

136 lines
5.4 KiB
Markdown
Raw 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.
# MoFin 自愈循环系统设计
> 版本: v1.0 | 最后更新: 2026-06-24
> 核心理念:体检发现问题 → TODO追踪 → 自动修复 → 次日体检验证,形成无人值守的修复闭环。
## 一、自愈循环架构
```
┌───────────────────────────────────┐
│ morning_health_check.py │
│ 每日 8:00(开盘前) │
│ │
│ 体检 7 层 43+ 项 │
│ 发现问题 → 写 TODO │
└──────────┬────────────────────────┘
│ TODO: health_fix_xxx
┌───────────────────────────────────┐
│ self-todo cron │
│ 每 2-3 小时自动执行 │
│ │
│ 读取 pending 任务 │
│ 按优先级逐个处理 │
│ 完成后 git commit + 标记完成 │
└──────────┬────────────────────────┘
│ git push
┌───────────────────────────────────┐
│ 次晨体检验证 │
│ │
│ 确认昨日问题已修复 → ✅ │
│ 问题依然存在 → ⚠️ 升级标记 │
└───────────────────────────────────┘
```
## 二、健康检查 → TODO 对接
### 对接点
morning_health_check.py 发现异常后:
```
1. 读当前 TODO 文件
2. 检查是否已有相同 issue 的 TODO(去重)
3. 如果没有 → 追加新 TODO:
- status: pending
- priority: 根据 severitycritical→high, error→medium, warn→low
- deps: 无
- title: "[体检发现] {问题描述}"
4. 如果有相同 TODO 且 status=completed →
- 说明昨天标记修复但今天仍然有问题 → 重新打开
- 修改 status=pending, priority 升一级
```
### TODO 字段映射
| 体检 severity | TODO priority | 预期修复时间 |
|---------------|---------------|-------------|
| critical | high | 当前 session / 下一个 self-todo |
| error | medium | 24h 内 |
| warn | low | 48h 内 |
## 三、xiaoguo 信号桥(知微消费 xiaoguo_scanner 产出)
### 问题
xiaoguo_scanner 每5分钟写 `signal_news` 表,但知微没有任何组件读取它。
### 解决方案
新增 `xiaoguo_signal_consumer.py`no_agent 脚本,每30分钟运行一次):
```
xiaoguo_signal_consumer.py (每30分, 盘中)
├── 读 mofin.db signal_news 表
│ WHERE source LIKE 'xiaoguo%'
│ AND (processed=0 OR processed IS NULL)
│ AND date(created_at) == today
├── 逐条处理:
│ ├── source=xiaoguo(看多信号):
│ │ ├── 检查是否已在自选/持仓
│ │ ├── 拉腾讯行情(实时价/PE/涨跌幅)
│ │ ├── 五维快速评估(大盘→行业→消息→基本面→技术)
│ │ ├── 决策:加自选 / 关注 / 跳过
│ │ └── 写入 decisions.json / watchlist.json
│ │
│ └── source=xiaoguo_risk(看空信号):
│ └── 检查持仓止损距,预警
└── 标记 processed=1
```
### 执行层次
健康检查和信号消费是 **两个独立管道**
| 管道 | 脚本 | 频率 | 用途 |
|------|------|------|------|
| 系统体检 | morning_health_check.py | 每日8:00 | 检查全部组件健康状态 |
| 信号消费 | xiaoguo_signal_consumer.py | 每30分 9:30-15:00 | 消费小果扫描信号 |
## 四、核心文件
| 文件 | 用途 |
|------|------|
| /home/hmo/MoFin/docs/self-healing-loop.md | 本文档 |
| /home/hmo/MoFin/scripts/morning_health_check.py | 体检脚本(已存在,需修改) |
| /home/hmo/MoFin/scripts/xiaoguo_signal_consumer.py | 信号消费脚本(新建) |
| /home/hmo/.hermes/profiles/position-analyst/todo.json | TODO 系统数据文件 |
## 五、TODO 集成修改计划
### morning_health_check.py 修改项
在 main() 函数末尾追加 TODO 写入逻辑:
```python
def write_todos_for_issues(report_entries):
"""将体检发现的异常写入 TODO 系统"""
todo_path = Path("/home/hmo/.hermes/profiles/position-analyst/todo.json")
# 读现有 TODO
# 去重(检查是否已有相同 issue)
# 追加新 TODO
# 写回
```
### xiaoguo_signal_consumer.py 新建
30分钟盘中循环,消费 signal_news 中的未处理 xiaoguo 信号。
### self-todo cron 适配
确保 self-todo cronb53435fbb38b 每小时多次运行)能识别并处理 `[体检发现]` 前缀的 TODO 项。