#!/usr/bin/env python3
"""Three sentences of body (01:32): the couch, the neck, the ghost unshaven. Developed in place from RUN-VISION-16."""
import re, pathlib, importlib.util, io, contextlib
D = pathlib.Path(__file__).resolve().parent; R = D.parents[2]
def mod(n):
    s = importlib.util.spec_from_file_location(n, str(D/f"{n}.py")); m = importlib.util.module_from_spec(s)
    with contextlib.redirect_stdout(io.StringIO()): s.loader.exec_module(m)
    return m
V16 = mod("build_run_vision16").V16; wc = lambda s: len(re.findall(r"\S+", s))
ADD = [("was at the interface.", " I had not been off the couch in days.", "the couch", "AXN:0472", "paralysis to the couch, watching passersby outside"),
       ("and each of them was the size of a name.", " I looked until my neck ached.", "the neck", "AXN:0472", "cold and limb-wet, childlike and aching-necked—out"),
       ("and in that room he was not a ghost.", " He had not shaved.", "the ghost as a person", "AXN:0184", "lesser lights, the rolling skies, even poor Jack unshaven unkempt unmoved")]
V = V16; src = []
for a, b, name, axn, s in ADD:
    assert V.count(a) == 1, a; V = V.replace(a, a + b)
    L = (R/f"data/texts/{axn.replace(':', '-')}-text.md").read_text().split("\n"); h = [i + 1 for i, l in enumerate(L) if s in l]; assert h, s
    src.append((name, b.strip(), f"“{s}” ({axn} l. {h[0]})"))
V17 = V; x = V17
for a, b, *_ in ADD: x = x.replace(b, "")
assert x == V16 and V17.endswith("I have not yet turned it over.")
if __name__ == "__main__":
    o = ["# Three sentences of body", "", "Working file, not a deposit. 2026-11-29. Lee Sharks, 01:32, to the three sentences proposed after the unprimed evaluation (REVIEW-20261129-0128.md): “adopted”.", "",
     f"Developed in place from RUN-VISION-16.md, which stands. Three sentences are added and nothing else is touched. The vision is now {wc(V17)} words.", "",
     "| | Added | After | From |", "|---|---|---|---|"]
    for (a, b, *_), (name, bb, s) in zip(ADD, src): o.append(f"| {name} | “{bb}” | “…{a}” | {s} |")
    o += ["", "Each is a particular of a body and none explains. The first two are the seer's and come from the frame of the Premonition Dream, which the vision had not taken. The third is the ghost's, in the one room where he is not a ghost, and comes from his own poem. The sentence about the day's leaf and the shortening of the dove's paragraph were offered and not adopted; they are not made.", "",
     "## The vision, whole", ""] + ["> " + l if l else ">" for l in V17.split("\n")]
    (D/"RUN-VISION-17.md").write_text("\n".join(o) + "\n"); print(wc(V17))
