#!/usr/bin/env python3
"""The vision as one document, with its bounds and its outline. The text is RUN-VISION-8's, unchanged; the part headings are apparatus."""
import re, pathlib, importlib.util, io, contextlib
D = pathlib.Path(__file__).resolve().parent
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
V = mod("build_run_vision9").V9
wc = lambda s: len(re.findall(r"\S+", s))
# (start of the part, title, what stands in it, grown in, what in the told life stands across from it)
PARTS = [
 ("The completion of Jack Feist", "The first sentence and the seer", "what the book is and whose; who was shown it and where that one was", "9", "scenes 9 and 12 (Lee Sharks, who printed them)"),
 ("Dark machines came for me", "The taking-up", "the seer taken, for the twenty-sixth time", "7", "none"),
 ("In the hour before day I was taken up", "The bones, the pearl, the machine", "space; the nested bones; the pearl in the ribs; “I put it there for you, on purpose”; the machine of people standing still", "3", "none. The told life has no beginning (SHAPE §2)"),
 ("Seven planets went around the machine", "The seven, and the book overhead", "the seven on their planets; the sky a book face down; the stars as numbers taken out", "2, 3", "scene 5 (a number taken out is not given again)"),
 ("In one of them stood a ghost.", "The ghost, the wheels, the hand", "the ghost as tree and book; the leaves; the bicycle of four wheels, a wheel in each; the hand with a number and an eye; the empty ring", "3, 4, 6", "scenes 7 and 8 (the pile; a line each morning)"),
 ("About that star, further out than the planets, twelve seats", "The twelve", "twelve seats seen from two stars; the making of the twelve from honors, in ruby; the maker among the made; the learned made small", "5, 7", "scenes 9 and 12 (the twelve named; two years that will not go in order); scene 11 (the journal)"),
 ("He said: That is the machine. I am a ghost. Write.", "The commission and the eight addresses", "“Write”; seven addresses, each sender named from the first seeing; an eighth to the youngest, who has no planet", "1, 3, 4", "scenes 1, 3, 5, 6, 13, 14 (the stations)"),
 ("I followed one leaf down.", "The leaf that goes by the seven", "seven acts on one leaf; one of the seven replaced; where leaves fall; the leaf that stands as a tree; the seven speaking", "6, 7", "scene 13 (the storehouse and its numbers); none for the passing itself"),
 ("Then a count went round the seven", "The count", "every second one put out; the seventh left; “the next ring begins”", "6", "none"),
 ("Before the moon I was shown one year on the pearl", "One year on the pearl", "six showings of the year, veiled; each changes something already seen, and five are met by a leaf", "5, 8", "scenes 17 to 22 (the history of the time)"),
 ("Then the machines that had brought me carried me up", "The thirty-sixth heaven", "up through the heavens of the twelve, three to each; the room; the book that is a body; the sentence not written down; the death partway; the going in", "7", "scene 7 (the front room), seen from the other side"),
 ("Then I saw a moon coming, and it was burning.", "The moon, the ring, the chain", "the moon that was turned twice; one of those standing lifts her head; one in the ring; the chain takes up", "3, 4", "none"),
 ("I looked at the back of my own hand.", "The seer's hand", "a number not in the book; not washed; not turned", "3", "scene 5 (the number copied on a hand)"),
]
idx = [V.index(p[0]) for p in PARTS]; assert idx == sorted(idx) and idx[0] == 0 and all(V.count(p[0]) == 1 for p in PARTS)
body = [V[a:b].strip() for a, b in zip(idx, idx[1:] + [len(V)])]; assert sum(wc(b) for b in body) == wc(V)
R = ["·", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII"]
sevens = [("the planets and those set on them", "III"), ("the addresses", "VI"), ("the acts on the leaf", "VII"), ("the count", "VIII")]
o = ["# The vision: one document, with its bounds and its outline", "",
 "Working file, not a deposit. 2026-11-28, at the author's word of 22:31: “lets get a combined vision document with its bounds and outline.” Built by `build_vision.py`. The text is that of RUN-VISION-9.md (the first sentence and the seer's frame set at 23:07; the year redeveloped at 22:54; the rest as RUN-VISION-7), unchanged, " + f"{wc(V)} words. The part headings are apparatus (an unnumbered opening and twelve numbered parts), set here for finding one's place. They are not part of the vision and it has none of its own.", "",
 "## 1. The bounds", "",
 "**Where it opens.** With a sentence that says what the book is: “The completion of Jack Feist, which the Book gave, to show the things that are done.” (the author, 23:04 and 23:07). Then the seer, in the first person: Lee Sharks, at the interface (the author, 23:12). Then the waking: the seer reads the day's leaf, and “the word that had slept in the case of my skull woke”. Then the taking-up. Nothing at the head supposes the twelve; they are first seen in part V. The collection begins with this book (PARAMETERS §14), so nothing before it tells a reader who is shown.", "",
 "**What it is.** The author, 23:14: “this is the vision of the logos being woken up in lee's skullcase”, and it is Jack Feist who wakes it. Everything after the third paragraph is what is seen in that waking.", "", "**The veil.** The history of the time stands in part IX under counts and measures, with no name (the author, 22:54: “not nero but 666 in the vision, tho we know its nero”). The told life names the same events outright.", "", "**Where it closes.** With the seer's own hand: “I have not yet turned it over.” Four reports have asked that this stay the last thing seen.", "",
 "**Its height.** It rises once, to a room in the thirty-sixth heaven (part X), and comes back down to the moon and the hand. The room is the one place in the vision that is also a place in the told life.", "",
 "**Its numbers.** One pearl. Four wheels, with a wheel in each. Seven: " + "; ".join(f"{a} ({b})" for a, b in sevens) + ". An eighth with no planet. Six showings of one year (IX): an earlier form of this document said seven, which was a miscount. Twelve seats. Thirty-six heavens, counted in passing and not shown. Twenty-six takings-up, of which this is the last told.", "",
 "**The two ends of the life.** The putting of the pearl is in part II. The death is in part X, as a place in a book that is not its last leaf. They stand eight parts apart.", "",
 "**Who speaks.** The seer, Lee Sharks, named twice at the head and nowhere after; a voice (parts II, IV, V, VIII); the ghost (part VI, the addresses); the seven together (part VII). The twelve do not speak and are not spoken to.", "",
 "**What it does not have**, against the bounds proposed in SHAPE.md §5.3 and not yet ruled on: a greeting and a closing frame (the letter); the two ends of the life set together at the centre; anything said to or by the twelve; the eight operators.", "",
 "## 2. The outline", "", "| | Part | Words | What stands in it | Grown in vision | Across from it in the told life |", "|---|---|---|---|---|---|"]
for r, p, b in zip(R, PARTS, body): o.append(f"| {r} | {p[1]} | {wc(b)} | {p[2]} | {p[3]} | {p[4]} |")
o += ["", f"Total {wc(V)} words. “Grown in vision” gives the run in which the part was first written or added to (RUN-VISION-3 to 9; the first two tests are superseded in stock). “Across from it” lists told scenes that hold the same relation. It does not mean the scene was unfolded from the part: so far every such scene was written before or beside its part, and none after it.", "",
 "### 2.1 Where parts would be added, if the proposed bounds are taken", "",
 "These are not written. They are set here so the outline shows its open places. Each waits on the author (SHAPE.md §5.3, §5.4).", "",
 "| Place | What would stand there | From |", "|---|---|---|",
 "| before I | written at 23:07: the first sentence and the seer's frame. Still open there: a greeting to those written to | Revelation's frame |",
 "| between V and VI, or VI and VII | the two ends of the life set together: the pearl put in, and the death | the paper's finding on Revelation 11 and 12 (AXN:0D8B l. 368) |",
 "| in V | something said to the twelve, or by them | nothing yet in the corpus has been read for this |",
 "| in IV | the eight who come and go at the wheels, two to each | The Eight Operators on Ezekiel's Wheels (AXN:0426) |",
 "| after XII | the letter's close | Revelation's frame; the Epistle |", "",
 "### 2.2 Four parts with nothing across from them", "",
 "Parts I, II, VIII and XI have no told scene. (The numbering is unchanged by the opening set before part I.) Under the rule of 21:49 they are where the told life would next be unfolded from: a beginning from II, an end told as a likeness from VIII and XI.", "",
 "## 3. The vision", ""]
for r, p, b in zip(R, PARTS, body):
    o += [f"### {r}. {p[1]}", ""] + ["> " + l if l else ">" for l in b.split("\n")] + [""]
o += ["## 4. Where each part is accounted for", "",
 "The places of the source for each part, with every quotation asserted at its line, are in the run files: RUN-VISION-3.md (stock, parts II to VI, XI, XII), RUN-VISION-4.md (nine developments), RUN-VISION-5.md §2 (the seats; the year), RUN-VISION-6.md §1 and §3 (the wheels; the leaf; the count), RUN-VISION-7.md §2 and §4 (the taking-up; the making of the twelve; the learned; the top), RUN-VISION-8.md (the year veiled), RUN-VISION-9.md (the first sentence and the seer). The grammar is VISION-GRAMMAR.md. The proposal on bounds is SHAPE.md §5.", ""]
(D/"VISION.md").write_text("\n".join(o)); print(wc(V), [wc(b) for b in body])
