#!/usr/bin/env python3
"""Archive the 2026-11-02 RUN NOTE out of SKILL.md into references/, leaving a pointer."""
import os, re

SK = "/home/kiro/.hermes/skills/social-media/x-account-monitor/SKILL.md"
REF = "/home/kiro/.hermes/skills/social-media/x-account-monitor/references"
os.makedirs(REF, exist_ok=True)

s = open(SK, encoding="utf-8").read()
print("before:", len(s))

start = s.index("### RUN NOTE (2026-11-02)")
end = s.index("### RUN NOTE (2026-11-03)")
note = s[start:end].rstrip() + "\n"

out = os.path.join(REF, "run-notes-2026-11-02.md")
with open(out, "w", encoding="utf-8") as f:
    f.write("# X Account Monitor -- RUN NOTE 2026-11-02\n\n"
            "Archived verbatim from SKILL.md on 2026-11-05 (SKILL.md was 86.0K and the\n"
            "2026-11-05 run note would have exceeded the 100K write limit).\n\n")
    f.write(note)
print("wrote", out, os.path.getsize(out), "bytes")

pointer = ("<!-- RUN NOTE 2026-11-02 archived verbatim to references/run-notes-2026-11-02.md\n"
           "     on 2026-11-05 (SKILL.md at 86.0K). The newest note in SKILL.md always wins. -->\n\n")
s = s[:start] + pointer + s[end:]
open(SK, "w", encoding="utf-8").write(s)
print("after:", len(s))
