"""临时脚本：在 session index 中搜索关键词"""
import json, sys

keywords = sys.argv[1:]
if not keywords:
    keywords = ["导出"]

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

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

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

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