# -*- coding: utf-8 -*-
import io, json, os, sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
BASE = r"D:\work buddy\2026-11-05-14-15-52"
OLD = "全库 A 169→170、B 178→177、C 1093 不变，需重做 1271→1266"
NEW = "全库 A 169→175、B 178→173、C 1093→1092，需重做 1271→1265"
OLDL = "密度 A 169→170、B 178→177、C 1093 不变，需重做 1271→1266"
NEWL = "密度 A 169→175、B 178→173、C 1093→1092，需重做 1271→1265"

B = os.path.join(BASE, "_heartbeat_baseline.json")
b = json.load(io.open(B, encoding="utf-8"))
n = 0
for i, a in enumerate(b["actions_this_round"]):
    if OLD in a:
        b["actions_this_round"][i] = a.replace(OLD, NEW)
        n += 1
json.dump(b, io.open(B, "w", encoding="utf-8"), ensure_ascii=False, indent=1)
print("baseline replaced", n, b["density_grade"])

L = os.path.join(BASE, "项目库扩充方案与进度台账.md")
led = io.open(L, encoding="utf-8").read()
assert led.count(OLDL) == 1, led.count(OLDL)
led = led.replace(OLDL, NEWL, 1)
io.open(L, "w", encoding="utf-8", newline="").write(led)
print("ledger fixed", len(led.encode("utf-8")))
