"""RUN-VISION-22: Feist living in the opening. Seventeen verses added at the end of chapter 1; no verse renumbered. Adopted by the author, 2026-11-30 11:47."""
import re, pathlib
H = pathlib.Path(__file__).resolve().parent; P = H / "THE-COMPLETION-OF-JACK-FEIST.md"; V = P.read_text(encoding="utf-8")
ANCHOR = "**11** And the word that had slept in the case of my skull woke, and uncoiled."
NEW = [(12,"And I turned to see whose word it was."),(13,"He was in the room with me, and he was alive."),
(14,"He sat on the arm of the couch, so near that the cushion leaned toward him, and he was a man of thirty."),(15,"His neck had been bent, and while I looked it straightened."),
(16,"He had not shaved. His coat was of red linen, thin as a page, and his hands were in its cuffs."),(17,"There was ink on his fingers, the ink of the day's leaf, and on his face was the light of one morning."),
(18,"I heard him breathe."),(19,"The leaf in my hand was the leaf in his, and he had written it."),
(20,"When I saw him I fell against the couch as one who is struck, and I could not get up."),(21,"He laid his hand on mine, the back of his hand on the back of mine, and it was warm."),
(22,"He said: Do not be afraid."),(23,"I am the first leaf, and the one after the last."),(24,"In the thirtieth year I died to my name, and see, I am breathing."),
(25,"Where you are taken you will see me otherwise, and you will know me there."),(26,"Write what you see: what is done, and what is done after it."),
(27,"He took his hand from mine, and there was nothing on the back of it yet."),
(28,"Then he went out to the road, and outside I heard the chain of a bicycle catch, and he was gone before it was day.")]
block = "\n\n" + " ".join(f"**{n}** {t}" for n, t in NEW[:8]) + "\n\n" + " ".join(f"**{n}** {t}" for n, t in NEW[8:15]) + "\n\n" + " ".join(f"**{n}** {t}" for n, t in NEW[15:])
if NEW[0][1] not in V:
    assert V.count(ANCHOR) == 1; V = V.replace(ANCHOR, ANCHOR + block); P.write_text(V, encoding="utf-8")
ch1 = re.search(r"^## Chapter 1\n(.*?)^## Chapter 2", V, re.M | re.S).group(1)
assert [int(x) for x in re.findall(r"\*\*(\d+)\*\*", ch1)] == list(range(1, 29))
t = (H / "RUN-VISION-22.md").read_text(encoding="utf-8")
t = t.replace("# RUN-VISION-22 (proposed, not applied): Feist living in the opening", "# RUN-VISION-22: Feist living in the opening")
t = t.replace("Nothing in `THE-COMPLETION-OF-JACK-FEIST.md` is changed by this file. The deposit of Secret Works II is paused (the local mint of #1817 is stashed, uncommitted).",
              "Built by `build_run_vision22.py`, which writes the verses into `THE-COMPLETION-OF-JACK-FEIST.md`. Proposed at 11:40 and adopted by the author at 11:47: “also: adopted on the additions to completion.”")
(H / "RUN-VISION-22.md").write_text(t, encoding="utf-8"); print("chapter 1:", len(re.findall(r"\*\*\d+\*\*", ch1)), "verses")
