import io

p = r"C:\Users\decid\Documents\projects\spt-claude-code\tools\claude-spt\src\hook.rs"
s = io.open(p, encoding="utf-8").read()

old = """                } else {
                    env.spt(&["api", "--adapter", ADAPTER, "state", "idle", eid, "--session-id", &sid], None, &[]);
                }
            }
        }"""
new = """                } else {
                    env.spt(&["api", "--adapter", ADAPTER, "state", "idle", eid, "--session-id", &sid], None, &[]);
                }
                // SEED THE IO CURSOR. A new session's FIRST `io-events` poll returns nothing and
                // seeds its cursor silently — by design, so a backlog is never replayed into a
                // turn-boundary hook. That makes the seeding poll indistinguishable from "nothing
                // happened", so whichever poll seeds is blind. If the first one were the frame
                // backstop at the first `Stop`, a commune ingested during the session's first turn
                // would be seeded PAST and its boundary lost — silently, and only on the first turn,
                // which is the hardest kind of miss to ever notice. Spend the seed here instead,
                // where returning nothing is the expected answer. [impl->REQ-COMMUNE-FRAME-BACKSTOP]
                env.spt(
                    &["api", "--adapter", ADAPTER, "io-events", eid, "--session-id", &sid, "--json"],
                    None,
                    &[],
                );
            }
        }"""
assert s.count(old) == 1, s.count(old)
io.open(p, "w", encoding="utf-8", newline="\n").write(s.replace(old, new))
print("ok")
