import os, sys
M = r"C:/Users/decid/.claude-spt/accounts/alt/projects/C--Users-decid-Documents-projects-spt-core/memory"
main = os.path.join(M, "MEMORY.md"); sub = os.path.join(M, "ACTIVE-WORK-INDEX.md")
mb = open(main, "rb").read(); sb = open(sub, "rb").read()
assert b"\r" not in mb and b"\r" not in sb, "CR present; abort"
lines = mb.split(b"\n")
# lines are 0-indexed here; L105..L118 (1-indexed) = idx 104..117
assert lines[99] == b"## Active work / project state", lines[99]
assert lines[103].startswith(b"- [v0.61.0..v0.68.0 arc entries]"), lines[103][:60]
moved = lines[104:118]
assert len(moved) == 14 and all(l.startswith(b"- [") for l in moved), [l[:40] for l in moved]
assert lines[118:] == [b""] or lines[118:] == [], lines[118:]   # file ends with newline after L118
prefix = b"\n".join(lines[:104]) + b"\n"
pointer = b"- [14 trap entries accumulated 2026-09-06..09-08](ACTIVE-WORK-INDEX.md#moved-2026-09-09) MOVED VERBATIM 2026-09-09 (byte identity asserted per line in the move script; zero dropped): api listen --once window, helper-stall CONFIRMED stay above; the rest = alchemy `--` flags, Bash 10-min cap, stopped ssh, perch-inherited identity, pool vs disk floor, kitsubito launch traps, TaskOutput, ephemeral-ports, tombstone, rig fetch port, gh run view --log, tag-shaped prose, curl -w partial, multi-target shortform.\n"
new_main = prefix + pointer
anchor = b"\n## Moved 2026-09-09 (VERBATIM from MEMORY.md, 14 entries)\n<a id=\"moved-2026-09-09\"></a>\n" + b"\n".join(moved) + b"\n"
new_sub = sb + anchor
# assertions before writing
assert new_main.startswith(prefix) and mb.startswith(prefix)
assert new_sub.startswith(sb)
for l in moved:
    assert l in new_sub and new_sub.count(l) == 1, l[:60]
    assert l not in new_main
open(main, "wb").write(new_main); open(sub, "wb").write(new_sub)
# re-read and re-verify
mb2 = open(main, "rb").read(); sb2 = open(sub, "rb").read()
assert mb2 == new_main and sb2 == new_sub
for l in moved:
    assert sb2.count(l) == 1
print("MOVED", len(moved), "MEMORY.md", len(mb), "->", len(mb2), "B; ACTIVE-WORK-INDEX.md", len(sb), "->", len(sb2), "B")
