From c3c1895896bf6596f55b451d7d084937704302a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=A5=E5=BE=AE?= Date: Sat, 27 Jun 2026 02:22:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E8=AF=BB=E8=84=9A=E6=9C=ACdocstring=E6=8E=A8=E7=AE=97=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=B5=81=EF=BC=8C=E4=B8=8D=E5=86=8D=E6=98=AF"?= =?UTF-8?q?=E6=9C=AA=E7=9F=A5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/morning_health_check.py | 53 +++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/scripts/morning_health_check.py b/scripts/morning_health_check.py index 518c7f8..bf28dfa 100755 --- a/scripts/morning_health_check.py +++ b/scripts/morning_health_check.py @@ -647,26 +647,55 @@ def run_check(item): if unregistered: ok = False detail = f"{len(gaps)}条待验证 + {len(unregistered)}个新组件未注册" - # 自动修复:把未注册的脚本加入注册表(占位) + # 自动修复:读脚本docstring,推算数据流 try: for s in unregistered: + script_path = HERMES_CRON_DIR.parent / "scripts" / f"{s}.py" + desc = "未知" + source_info = f"{s}.py" + consumer_info = "未知" + if script_path.exists(): + content = script_path.read_text() + # 提取docstring + import re as rr2 + doc_match = rr2.search(r'"""(.*?)"""', content, rr2.DOTALL) + if doc_match: + doc_text = doc_match.group(1).strip() + desc = doc_text.split('\\n')[0][:80] + # 尝试从docstring中提取管道信息 + pipe_match = rr2.search(r'管道[::].*?(?=\\n|$)', doc_text) + if pipe_match: + consumer_info = pipe_match.group(0).replace('管道','').strip(':: ') + # 检测写入模式 + if 'signal_news' in content: + consumer_info = 'signal_news表' + if 'macro_risk_state' in content: + consumer_info = 'macro_risk_state.json' + if 'watchlist' in content.lower(): + consumer_info = 'watchlist.json / decisions.json' + if 'INSERT INTO' in content: + for tbl in ['todos', 'price_events', 'macro_context_log', 'accuracy_stats']: + if tbl in content: + consumer_info = f'{tbl}表' + if '.write_text' in content or 'json.dump' in content: + for path in ['macro_risk_state', 'macro_context', 'market', 'portfolio', 'decisions']: + if path in content: + consumer_info = f'{path}.json' reg["pipelines"].append({ "id": f"auto-{s}", - "name": f"{s}(自动发现)", - "source": f"{s}.py (自动发现)", - "consumer": "未知(需确认)", - "end_user": "未知(需确认)", + "name": desc[:60], + "source": source_info, + "consumer": consumer_info, + "end_user": "待确认", "verified": False, - "verified_at": None, - "gap": "自动发现的组件,数据流待确认", - "fix": "手动编辑pipeline_registry.json完善此项", - "deadline": "发现后3天内" + "gap": f"自动发现({desc[:60]})", + "fix": "手动编辑pipeline_registry.json完善此项" }) open(str(DATA / "pipeline_registry.json"), 'w').write( j2.dumps(reg, ensure_ascii=False, indent=2)) - detail += f" → 已自动添加{len(unregistered)}条占位记录" - except Exception: - pass + detail += f" → 已自动注册{len(unregistered)}个(含推断)" + except Exception as e: + detail += f" (自动注册异常:{str(e)[:30]})" elif gaps: ok = False detail = f"{len(gaps)}条管道未验证: {', '.join(gaps[:5])}"