From 2138ae2bfd009315f21f1d1b3c6b406fcdfcdcb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=A5=E5=BE=AE?= Date: Tue, 7 Jul 2026 10:14:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=A3=E7=A0=81=E7=BA=A7=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E7=BA=A6=E6=9D=9F=E2=80=94=E2=80=94LLM=E7=9C=8B?= =?UTF-8?q?=E5=88=B0=E6=95=B0=E6=8D=AE=E5=89=8D=E5=BF=85=E9=A1=BB=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E9=87=8D=E8=AF=84(stale/=E6=97=A0=E7=AD=96=E7=95=A5),?= =?UTF-8?q?=20=E4=B8=8D=E7=AD=89TODO=E5=BC=82=E6=AD=A5=20mofin=5Fcollect.p?= =?UTF-8?q?y=E6=AD=A5=E9=AA=A40=E6=94=B9=E9=80=A0:=20=20=20stale(>4h?= =?UTF-8?q?=E6=9C=AA=E6=9B=B4=E6=96=B0)=20=E2=86=92=20=E7=AB=8B=E5=8D=B3?= =?UTF-8?q?=E8=B0=83reassess=5Fwith=5Fcontext()=E5=BC=BA=E5=88=B6=E9=87=8D?= =?UTF-8?q?=E8=AF=84,=20=E4=B8=8D=E9=9D=A0TODO=E5=BC=82=E6=AD=A5=20=20=20?= =?UTF-8?q?=E6=97=A0=E7=AD=96=E7=95=A5(holding=5Fstrategies=E6=97=A0?= =?UTF-8?q?=E8=AE=B0=E5=BD=95)=20=E2=86=92=20=E7=AB=8B=E5=8D=B3=E8=B0=83re?= =?UTF-8?q?assess=5Fwith=5Fcontext()=E5=88=9B=E5=BB=BA=E7=AD=96=E7=95=A5?= =?UTF-8?q?=20=20=20=E5=8F=AA=E6=9C=89=E9=87=8D=E8=AF=84=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E5=90=8E=E6=89=8D=E5=85=81=E8=AE=B8LLM=E7=BB=99=E5=87=BA?= =?UTF-8?q?=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/mofin_collect.py | 62 +++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/scripts/mofin_collect.py b/scripts/mofin_collect.py index f1956b08..8781ccbd 100644 --- a/scripts/mofin_collect.py +++ b/scripts/mofin_collect.py @@ -62,33 +62,61 @@ try: hours_stale = 999 if hours_stale > 4: - # 策略过期→创建TODO触发重评 stale_count += 1 - todo_sql = """ - INSERT OR IGNORE INTO todos - (title, code, fix_action, source, priority, status, created_at) - VALUES (?, ?, 'reassess_strategy', 'freshness_check', 'high', 'pending', ?) - """ - cur.execute(todo_sql, ( - f"策略过期需重评: {code} {name} ({hours_stale:.0f}h未更新)", - code, - now.isoformat() - )) - print(f" ⚠️ STALE {code} {name}: {hours_stale:.0f}h未更新 → 已创建重评TODO", flush=True) + # 强制代码级约束:立即执行重评,不等TODO异步处理 + # 在LLM看到数据前,策略必须是新鲜的 + try: + from strategy_lifecycle import reassess_with_context + result = reassess_with_context( + code, name, r["price"], + r.get("cost", 0), r.get("shares", 0), + r["action"] or "" + ) + if result and result.get("action"): + print(f" 🔄 FORCE_REASSESS {code} {name}: {hours_stale:.0f}h过期→已立即重评→{result['action'][:60]}", flush=True) + else: + print(f" ⚠️ FORCE_REASSESS {code} {name}: 重评返回空结果", flush=True) + except Exception as e: + print(f" ❌ FORCE_REASSESS {code} {name} 失败: {e}", flush=True) + # 创建TODO作为兜底 + todo_sql = """ + INSERT OR IGNORE INTO todos + (title, code, fix_action, source, priority, status, created_at) + VALUES (?, ?, 'reassess_strategy', 'freshness_check', 'high', 'pending', ?) + """ + cur.execute(todo_sql, ( + f"策略过期需重评: {code} {name} ({hours_stale:.0f}h未更新)", + code, + now.isoformat() + )) + print(f" ⚠️ STALE {code} {name}: {hours_stale:.0f}h未更新 → 已强制重评", flush=True) else: fresh_count += 1 print(f" ✅ FRESH {code} {name}: {hours_stale:.1f}h前更新", flush=True) else: no_strategy_count += 1 - print(f" ❌ NO_STRATEGY {code} {name}: 无策略记录", flush=True) - + # 无策略→立即执行重评创建策略(代码级约束:不允许无策略就输出建议) + try: + from strategy_lifecycle import reassess_with_context + result = reassess_with_context( + code, name, r["price"], + r.get("cost", 0), r.get("shares", 0), + "" + ) + if result and result.get("action"): + print(f" 🔄 CREATE_STRATEGY {code} {name}: 无策略→已创建→{result['action'][:60]}", flush=True) + else: + print(f" ⚠️ CREATE_STRATEGY {code} {name}: 重评返回空", flush=True) + except Exception as e: + print(f" ❌ CREATE_STRATEGY {code} {name} 失败: {e}", flush=True) + conn.commit() conn.close() - + total = len(rows) - print(f"策略检查完成: {total}只持仓, {fresh_count}新鲜, {stale_count}过期(已创TODO), {no_strategy_count}无策略", flush=True) + print(f"策略检查完成: {total}只持仓, {fresh_count}新鲜, {stale_count}过期(已强制重评), {no_strategy_count}无策略(已创建)", flush=True) if stale_count > 0 or no_strategy_count > 0: - print(f"⚠️ LLM注意: 有{stale_count + no_strategy_count}只持仓策略不是最新状态, 禁止对这些股给出操作建议", flush=True) + print(f"⚠️ 重评完成: {stale_count + no_strategy_count}只已强制刷新, LLM可基于最新策略给出建议", flush=True) except Exception as e: print(f"WARN: strategy_freshness_check跳过 ({e})", flush=True)