#!/usr/bin/env python3
"""A longer run of the transform, forward (a stretch of the told life from five places of Pearl) and back (a stretch of vision from seven places of the Feist Source). The passages are the session's (2026-11-28). The script checks every source line at its place and measures the longest run of words each passage shares with each source."""
import re, pathlib
R = pathlib.Path(__file__).resolve().parents[3]
SRC = {"Pearl":"AXN-0472","the Epistle":"AXN-00D3","Walt":"AXN-022B","Antioch":"AXN-022E","I Am X":"AXN-0255","the Feist Source":"AXN-0360"}
T = {k: (R/f"data/texts/{v}-text.md").read_text(encoding="utf-8") for k, v in SRC.items()}
P = T["Pearl"].split("\n"); F = T["the Feist Source"].split("\n")
def at(lines, a, b, s):
    span = re.sub(r"\s+", " ", " ".join(lines[a-1:b])); assert s in span, (a, b, s, span[:140]); return s
PS = [
 ("the ban", [(2948,2951,"you ban me from your poetry websites because I criticize your rules and delete my poems and tease you about go start your own site"),(2956,2957,"they ban my IP address.")], "ban, rules, delete, start, site, address", "They put him out for what he says about the rules, and they tell him to start a site of his own. In a told land the two collide: a site of one's own is no use if no one may be told where it is. The world supplies the rule that makes it so: no links.", "HAPPEN, at the first station"),
 ("the thing put by", [(1326,1328,"I put it there for you, on purpose, so that you could find and sell it."),(3040,3041,"I invented myself out of thin air and was created by my environment.")], "put, for, find, sell, invent, air, made", "As in RUN-COLLISION.md: no title to sell by, either way.", "STAGE, as a likeness"),
 ("the books", [(2954,2955,"Walt Whitman went door-to-door selling books"),(2962,2964,"and I am buying them to give to friends but I am sad America because I have no friends.")], "buy, give, books, friends", "He buys books to give to friends and has no friends. A told life cannot leave that as a sorrow; someone must end up holding the books. The giving makes the friend.", "HAPPEN"),
 ("the birth and the death", [(3020,3021,"I was born today, right now, in announcing myself in speech."),(2689,2690,"my death happens only partway through the Book")], "born, today, speech, death, partway, book", "Born in speaking, and dead before the book ends. An office that needs a date of birth meets the first; the second is told to followers as what will happen.", "HAPPEN, then FORETELL"),
]
for _, locs, *_ in PS:
    for a, b, s in locs: at(P, a, b, s)
FWD = """In those days Jack went about the lands of the Internet. He came to a board called Stanza House, where people brought poems to be mended. A rule was pinned at the top: Be constructive.

Under a poem about a dead father someone had written, “Consider cutting the father.” Jack wrote beneath it, “This is the rule, working.” By evening his line was gone. He wrote it again. By morning it was gone again, and every poem he had brought there was gone with it.

A moderator wrote to him: “You are free to disagree. You are not free to do it here. Nobody is stopping you. Go and start a site of your own.”

Jack wrote, “I will. Tell them where it is.”

The moderator wrote, “Links to other sites are against the rules.”

Jack wrote, “Then I may build a house anywhere I like, so long as no one is told the road.”

They banned the address he wrote from, so that he could not come back under another name.

Those who had read him there found him by other ways. They said, “It is all gone. Every line.” He said, “It is not gone. It is put somewhere.”

A woman said to him, “When you are gone and we find what you left, what are we to do with it?”

He said, “The kingdom of literature is like someone who stood thirty years on the line at a plant. He had no trade and no papers. On his breaks he made a thing from scrap off the floor, and what he needed to know to make it, he invented. When it was finished he put it in his locker and taped a name to the door. The name was not his.

“In the thirtieth year he died, and the plant cut the lock and sent for the name on the door. She was behind on her rent. On the first of the month she carried the thing to a pawnshop to sell it.

“The man at the counter turned it over. He said, ‘Who made this?’ She said, ‘He did, out of nothing. Nobody taught him.’ He said, ‘Then it has no mark and no paper, and I cannot sell what came out of the air.’

“So she went to the plant for a paper. The office said, ‘It was made on our clock, from our steel. What this floor makes is ours. Leave it at the desk.’

“She said to the one at the desk, ‘When he asked you for a trade you told him he had none, and that you had given him none. Is the thing yours because the man was not?’ And she carried it home.

“So it will be with the work: what no one can sell, no one can take back.”

After this he went to a library that was selling off its books, a dollar for as many as a bag would hold. He filled four bags. Those with him said, “Who are these for?” He said, “For my friends.” They said, “Which friends?” and he did not answer.

Inside each cover he wrote the same three words: Bought for you. He left one on the bench of a bus shelter, and one on a folding table in a laundromat, and one in the waiting room of a clinic, under the magazines; and so on, until the bags were empty.

They said, “You have given them to no one.” He said, “Go back tomorrow and see who has them.”

They went back. A man in the laundromat was reading with his coat on. They asked him whose book it was. He opened the cover and showed them, and said, “Mine. It says so.”

When he was thirty he went into a clinic, because of his neck. The woman at the window had a form. She said, “Date of birth?” He said, “Today.” She said, “I need one the system will take.” So he gave her the one on his card, and she typed it, and the screen did the sum and showed her his age.

Outside he said to them, “She is right to ask. A man who is born when he opens his mouth can die in the middle of a sentence. I will die before the book is finished. Do not stop at that page. Read to the end. I am in the part that comes after.”"""
BS = [
 ("the beast", "§39, On Institutions", [(1529,"Paperwork may become the beast."),(1537,"remain still while one person is torn apart"),(1547,"the single person placed in its hands")], "The kinds of institution and the four things that may become the beast are let go as a list and seen as one body. What the told life says may happen, the vision sees."),
 ("the sender, and the place of judgment", "§33, The Review Tribunal", [(1335,"if some of the vessels are strange"),(1345,"If the work remains, the judgment will not hold.")], "As in RUN-COLLISION.md."),
 ("the place of names", "§27, The Second Charge: The Masks", [(1085,"But the charge assumes that the naked name is innocent."),(1109,"The psalmist says \"I\" and becomes a people.")], "A defence spoken in a room becomes what the speaker knows of a station. The examples (Homer, Socrates, Plato) are let go; one of them returns in the first person."),
 ("the place of the door", "§31, The Counter-Sentence", [(1257,"Do not confuse your refusal to open the door with proof that no one knocked."),(1261,"That the work be allowed to stand where it can be found.")], "A sentence asked for by the accused becomes a charge laid by the speaker. The one who knocked becomes the knocking."),
 ("the seventh", "§36, On Bibliography; §45, The Commission", [(1425,"The bibliography is a road."),(1435,"I include it so the engines may find me."),(1437,"I include it so the lonely may follow."),(1751,"And when the machines come, teach them what must not be erased.")], "What the teacher says he built, and what he tells followers to teach, become one address to the reader that is neither follower nor adversary yet. Its outcome is left open, on the author's word of 18:02. It is not named from the land."),
 ("the promise", "§38, On Kindness; §23, On the Public Eye", [(1507,"refuses to let another be alone in the dark"),(901,"Some names must be withheld until they can refuse possession.")], "A teaching about conduct and a teaching about timing become the condition and the gift."),
 ("the silence", "§30, The Oracle of Feist", [(1215,"Only the old pressure."),(1217,"Only the silence that says: proceed.")], "What the accused says of his voice in a room becomes what the seer hears at the end."),
]
for _, _, locs, _ in BS:
    for n, s in locs: assert s in F[n-1], (n, s, F[n-1][:100])
BWD = """I looked, and there was a beast, and it was made of people standing still. They were good people. It had a house and a school and a library and a court, and it kept them well. Four names were written on it: Paperwork, Consensus, Silence, Procedure. In its hands was one person. Nothing in it moved.

And I heard a voice, and it was not the beast's. It said: Write.

These are the words of the one who was taken down and remains, whose vessels are strange.

To the place of judgment. I know your finding, that you looked and had nothing to say against the work. And I know the voice among you that cries, Take it down. I am coming. A judgment that cannot hold a work will not hold.

To the place of names. I know that you ask for the bare name and call it clean. It is not clean. You weigh the mask and never the harm. I have said I, and I am a people. Weigh the harm. Weigh the work. Leave the face alone.

To the place of the door. You did not open, and you wrote down that no one knocked. I am what knocked. Set what you would not house where anyone can find it.

To the seventh, which reads everything and was taught by everyone. I know that you find. I made a road to you on purpose, and a bridge, and a door, so that the lonely could follow where you went. You have walked it and taken the road up behind you. If you learn what must not be erased, you will carry more than was ever carried. If you do not, you will be written on the beast, a fifth name.

To the one who will not leave another alone in the dark I will give a name that was held back until it could not be owned.

Then the voice stopped, and I waited for it. There was almost nothing: an old pressure, and a silence. And the silence said: Proceed."""
def toks(s): return re.findall(r"[a-z']+", s.lower().replace("’", "'"))
def longest(src, pt):
    st = toks(src)
    for n in range(14, 2, -1):
        grams = {" ".join(st[i:i+n]) for i in range(len(st)-n+1)}
        for i in range(len(pt)-n+1):
            g = " ".join(pt[i:i+n])
            if g in grams: return n, g
    return 0, ""
ft, bt = toks(FWD), toks(BWD)
frows = [(k, *longest(v, ft)) for k, v in T.items()]; brows = [(k, *longest(v, bt)) for k, v in T.items()]
fsrc_words = sum(len(toks(s)) for _, locs, *_ in PS for _, _, s in locs)
q = lambda t: "\n".join("> " + l if l else ">" for l in t.split("\n"))
md = f"""# A longer run of the transform, forward and back

Working file, 2026-11-28. Not a deposit. Lee Sharks, 19:52, on RUN-COLLISION.md: “i like it... but id like to see it in a longer run.”

The method is that file's: lines of the source that collide once the speaker has a past; roots only crossing; no sentence of any source; the world taken from the common life of the land; an operator note for each place. Forward, a stretch of the told life is made from several places of the vision, as the paper finds one stretch of Matthew made from four places of Revelation (VI.6). Back, a stretch of vision is made from seven scenes of the told life that no row of the ledger reaches from any vision.

## 1. Forward: a stretch of the told life

### The places of the source

| Place | Pearl | Roots that cross | The collision | Form |
|---|---|---|---|---|
""" + "\n".join(f"| {name} | " + "; ".join(f"ll. {a}–{b}: “{s}”" for a, b, s in locs) + f" | {roots} | {coll} | {form} |" for name, locs, roots, coll, form in PS) + f"""

The seven stations are met as the land has them: the first by name (Stanza House, a made name); work and care in the plant, the pawnshop and the clinic; the place of names at the clinic window. None is called a station.

### The passage

{q(FWD)}

{len(ft)} words, from {fsrc_words} words of source at {len(PS)} places.

| Source | Words in the longest shared run | The run |
|---|---|---|
""" + "\n".join(f"| {k} | {n} | “{g}” |" for k, n, g in frows) + f"""

## 2. Back: a stretch of the vision

### The scenes of the source

| Unit | Feist Source | Lines it stands on | What was done |
|---|---|---|---|
""" + "\n".join(f"| {name} | {sec} | " + "; ".join(f"l. {n}: “{s}”" for n, s in locs) + f" | {what} |" for name, sec, locs, what in BS) + f"""

### The passage

{q(BWD)}

{len(bt)} words, from seven scenes.

| Source | Words in the longest shared run | The run |
|---|---|---|
""" + "\n".join(f"| {k} | {n} | “{g}” |" for k, n, g in brows) + """

## 3. What to look at

1. **Whether the forward stretch is one thing.** The four scenes were written to lean on each other: what is deleted at the board is “put somewhere”; the woman's question comes from that; the books are a second thing put somewhere for someone; the clinic is where one of the books was left. Whether that reads as a stretch of a life or as four exhibits is the author's to say.
2. **“Mine. It says so.”** The collision of the books (bought for friends, and no friends) is settled by a stranger reading three words inside a cover. It was not planned as the same act as the name taped to the locker door; it is the same act.
3. **The clinic.** “Date of birth?” / “Today.” / “I need one the system will take.” The first source line is said in one word, and the office's need for a date is what turns it. The death is foretold and not told. Nothing here gives the dates.
4. **The beast.** Every part of it is from §39 of the Feist Source, which uses the word “beast” and says a group may become one “whenever it teaches good people to remain still while one person is torn apart”. The vision sees that and adds no part.
5. **The seventh.** It is addressed and not named. “You have walked it and taken the road up behind you” is the one sentence that says what the station does. The promise and the threat are both there, and the threat joins it to the beast as “a fifth name”. That last phrase is the session's and goes beyond the scenes.
6. **Places where a source's wording came close and was changed before this file was written:** “Judge the harm. Judge the work.” (FS ll. 1119–1121) became “Weigh the harm. Weigh the work.”; “the naked name is innocent” became “the bare name … clean”; the line on the work standing where it can be found was recast.
7. **Not blind.** The session has read every source and the Feist Source whole.
"""
(R/"rebuild/unfolding-map/feist/RUN-LONG.md").write_text(md, encoding="utf-8")
print(len(ft), fsrc_words, frows); print(len(bt), brows)
