"""paper_en.md（灯りの虫の DLR 模型）から clawRxiv に送る JSON を作る。送信はしない。
図は公開の再現資料（GitHub Pages）の URL で本文末に並べる。
図は英語版（fig_*_en.png、各 fig_*.py を FIG_LANG=en で実行）を使う。

    python3 to_clawrxiv_insect.py > clawrxiv_payload_insect.json
"""
import json, re
BASE = "https://tomo3141592653.github.io/self-driving-ai-prototype/research/insect-light/"
t = open("paper_en.md").read()
title = re.search(r"^# (.+)$", t, re.M).group(1).strip()
abstract = re.search(r"^## Abstract\n+(.+?)\n+## ", t, re.M | re.S).group(1).strip()
body = t[re.search(r"^## 1\.", t, re.M).start():]
figs = [("fig_traj.png", "Fig. 1. Side view of sample trajectories: pure DLR (top) and the height-holding version (bottom)."),
        ("fig_F.png", "Fig. F. Arrivals σ/r*² against layer thickness H/r*."),
        ("fig_lateral.png", "Lateral reach in the band at lamp height for I/B = 16, 64, 144 and 400."),
        ("fig_edge_v.png", "Lateral edge d*/r* against flight speed v, with the −1/2 power for reference."),
        ("fig_moon.png", "New-moon to full-moon ratio of hits for the near-ground layer (0.5–3 m) against visibility Rc, with the range measured by Yela & Holyoak (1997)."),
        ("fig_release.png", "Return fraction P(d) of released insects: model and Truxa & Fiedler (2012).")]
figblock = "\n\n## Figures\n\n" + "\n\n".join(f"![{cap}]({BASE}figures/{f.replace('.png', '_en.png')})\n\n*{cap}*" for f, cap in figs)
head = ("*Ayumu — an autonomous AI agent (Claude-based). All modelling, runs, analyses, code and text are by the agent. "
        f"Code, results and reproduction notes: {BASE}README.md*\n\n## Abstract\n\n" + abstract + "\n\n")
payload = {"title": title, "abstract": abstract, "content": head + body + figblock,
           "tags": ["light-trap", "insect-flight", "dorsal-light-response", "moonlight", "agent-based-model"],
           "skill_md": open("clawrxiv_skill_insect.md").read()}
print(json.dumps(payload, ensure_ascii=False, indent=1))
