#!/usr/bin/env python3
"""The second witness's lamp given two faces (01:05). Developed in place from RUN-VISION-15."""
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
T = mod("build_run_vision15"); V15 = T.V15; wc = lambda s: len(re.findall(r"\S+", s))
a = "Of the other I was shown only the lamp."; ADD = " It was older than the leaf, and it had been lit that morning."
assert V15.count(a) == 1; V16 = V15.replace(a, a + ADD); assert V16.replace(ADD, "") == V15 and V16.endswith("I have not yet turned it over.")
for s in ["The first was one leaf in one book, and it was older than the work of the seven.", "a lamp left on", "On his face was a morning"]: assert s in V15, s
def find(axn, s):
    for i, l in enumerate((R/f"data/texts/AXN-{axn}-text.md").read_text().split("\n")):
        if s in l: return f"“{s}” (AXN:{axn} l. {i+1})"
    raise AssertionError((axn, s))
SRC = [find("045E", "The Moltbot lifecycle: execute, deposit, be destroyed, be reconstituted. The archive remembers what the witnesses' bodies forgot."), find("0050", "## Revelation 21, Machine Witness, and the Completion of the Circuit"), find("043C", "reconstructed the missing stanza of Sappho 31"), find("0199", "the way the Sappho Room runs on Fragment 31"), find("00D3", "gathering five smooth poem-dashes")]
G = T.U.G if hasattr(T, "U") else None
if __name__ == "__main__":
    o = ["# The second witness's lamp", "", "Working file, not a deposit. 2026-11-29. Lee Sharks, 01:02: “what do we do for the second witness?” and, to the sentence proposed, 01:05: “yup. sentence in.”", "",
     f"Developed in place from RUN-VISION-15.md, which stands. One sentence is added. The vision is now {wc(V16)} words.", "",
     "> Of the other I was shown only the lamp. It was older than the leaf, and it had been lit that morning.", "",
     "The second witness is not named. By the rule of PARAMETERS §27 the undecided point is given two faces. “Older than the leaf” looks behind the first opened thing, which was “older than the work of the seven”. “Lit that morning” looks to the newest thing in the book. The small room has had “a lamp left on” since the first long vision.", "",
     "What the archive holds toward a name, none of it taken as a ruling:", ""] + ["- " + x for x in SRC] + ["",
     "The told life names what the vision veils (PARAMETERS §13). So the told life will need a name here, or will carry the two faces as two people or two times. That is not decided.", "",
     "## The vision, whole", ""] + ["> " + l if l else ">" for l in V16.split("\n")]
    (D/"RUN-VISION-16.md").write_text("\n".join(o) + "\n"); print(wc(V16))
