"""临时脚本：宽泛搜索 session index"""
import json

with open("docs/audit/session_logs/_session_index.json", "r", encoding="utf-8") as f:
    data = json.load(f)

sessions = data.get("sessions", [])

# 宽泛关键词列表，任一匹配即输出
keywords = ["台费", "储值", "Excel", "csv", "settlement", "balance", "stored_value", "流水", "营业额", "收入", "报表"]

results = []
for s in sessions:
    desc = s.get("description", "")
    summary = s.get("summary", {})
    files = summary.get("files_modified", [])
    all_text = (desc + " " + " ".join(files)).lower()
    matched = [kw for kw in keywords if kw.lower() in all_text]
    if matched:
        results.append({
            "id": s.get("sessionId", ""),
            "time": s.get("startTime", ""),
            "desc": desc[:200],
            "matched": matched,
        })

# 按时间倒序
results.sort(key=lambda x: x["time"], reverse=True)

print(f"Found {len(results)} results")
for r in results[:20]:
    print(f"\n--- {r['time']} ---")
    print(f"ID: {r['id']}")
    print(f"Matched: {r['matched']}")
    print(f"Desc: {r['desc']}")
