#!/usr/bin/env python3
"""Ledger rows, Pearl and the Epistle to the Feist Source: every quotation checked at its line, rarity counted by FS section. Rows are the session's reading (2026-11-28); this script checks and tables them, it does not find them."""
import re, pathlib, json
R = pathlib.Path(__file__).resolve().parents[3]
T = {"P": (R/"data/texts/AXN-0472-text.md").read_text(encoding="utf-8").split("\n"),
     "E": (R/"data/texts/AXN-00D3-text.md").read_text(encoding="utf-8").split("\n"),
     "W": (R/"data/texts/AXN-022B-text.md").read_text(encoding="utf-8").split("\n"),
     "X": (R/"data/texts/AXN-0255-text.md").read_text(encoding="utf-8").split("\n"),
     "A": (R/"data/texts/AXN-022E-text.md").read_text(encoding="utf-8").split("\n"),
     "F": (R/"data/texts/AXN-0360-text.md").read_text(encoding="utf-8").split("\n")}
F = T["F"]; sec = {}; cur = "front"
for i, l in enumerate(F, 1):
    m = re.search(r"## (\d+)\. ", l)
    if m: cur = "§" + m.group(1)
    elif "## The Codex Found in Sleep" in l: cur = "prologue"
    elif "## The Non-Erasure of Feist" in l: cur = "coda"
    sec[i] = cur
def secs(pattern):
    return sorted({sec[i] for i, l in enumerate(F, 1) if re.search(pattern, l, re.I)}, key=lambda s: (s[0] != "§", int(s[1:]) if s[0] == "§" else 0))
def q(t, n, s):
    ok = s in T[t][n-1]
    if not ok: raise SystemExit(f"MISS {t}{n}: {s!r} | {T[t][n-1][:90]!r}")
    return f"{ {'P':'Pearl','E':'Epistle','F':'FS','W':'Walt','X':'I Am X','A':'Antioch'}[t] } l. {n}: “{s}”"
ROWS = [
 ("L01","R","commerce opposed in its terms; the gift's sale refused by the buyer", [("P",1326,"Inside his tiny ribcage there is a pearl. I put"),("P",1327,"it there for you, on purpose, so that you could find"),("P",1328,"and sell it.")], [("F",701,"If you bring a real pearl to a vanity jeweler, do not be surprised when he cannot price it.")], r"pearl.*(pric|jewel|scale|apprais)|(pric|jewel|scale|apprais).*pearl", "In Pearl the one given the pearl is to find and sell it. In FS the one who brings it cannot get it priced."),
 ("L02","R","foretold in the vision, it happens in the told life (time: will / did); another thing in the same place (rib-cage, archive)", [("P",1557,"when at last they cough out my bones"),("P",1568,"cage of ribs, for you to find,"),("P",1570,"a final poem")], [("F",1693,"And the archive opened."),("F",1715,"And they knew him in the opening of the archive")], r"archive opened|opening of the archive", "The dead speaker's remains are opened and the work is found inside by those it was left for."),
 ("L03","R","time: will / did; a condition made a thing (nothing taken, bread carried out)", [("P",1516,"Early one morning I will rise from my dingy sleeping mat"),("P",1517,"and walk into the desert wastes, taking nothing with"),("P",1520,"until, years later, I return")], [("F",225,"He entered the desert."),("F",285,"After many years, Feist knew it was time to return."),("F",289,"He came out carrying bread.")], r"\bdesert\b", "Going out to the desert, years, the return."),
 ("L04","W","ENACT: a title claimed by the speaker becomes a list of begettings", [("P",4502,"of the Good Gray Poet."),("P",4504,"I claim this mantle: King of May.")], [("F",113,"The Romantics begat Whitman."),("F",115,"Whitman begat Ginsberg."),("F",117,"Ginsberg begat Jack Feist.")], r"Ginsberg", "The Good Gray Poet is Whitman and the King of May is Ginsberg; the mantle claimed is the line told."),
 ("L05","R","TURN, the doer: the speaker announces himself; a voice names the teacher", [("P",3020,"and also I was born today, right now, in announcing myself"),("P",3040,"I invented myself out of thin air and was created by my")], [("F",143,"Then a voice came over the waters of the body and said:"),("F",155,"You will be called Jack Feist"),("F",173,"He became his own mother and father.")], r"his own mother and father|You will be called", "A birth by speech, of one who is his own maker."),
 ("L06","R","TURN, the doer: what the speaker does in the vision the adversary does in the told life", [("P",3043,"I am a woman and also a child."),("P",3047,"I am a great hulking beast of a muscular man"),("P",3055,"I am no one at all.")], [("F",329,"Each name came out wearing Feist's face."),("F",343,"I am the name behind the names."),("F",355,"All unresolved persons will be indexed under one name.")], r"I am the name behind|indexed under one name", "One 'I am' takes every person into itself. In Pearl it ends 'no one at all'; in FS, 'one name'."),
 ("L07","W","KEEP: said of the adversaries in the letter, of the adversary in the told life", [("E",82,"and containing within themselves all the names in history")], [("F",321,"And all the names of history moved through it.")], r"names of history", "The letter says it of the academics who make the human being a label."),
 ("L08","W","ALTERED, another thing in the same place: he / it (the Book)", [("E",74,"He came unto his own, and his own knew him not.")], [("F",77,"It came to its own."),("F",79,"Its own did not recognize it.")], r"came to its own", "The letter cites it as written; FS tells it of the Book."),
 ("L09","W","KEEP: done to the speaker, done to the teacher (person and time only)", [("P",2948,"I am sad America because you ban me from your poetry"),("P",2950,"and delete my poems"),("E",72,"mocked, beaten, stoned, and banned")], [("F",1351,"They took down the posts."),("F",1353,"They closed the accounts."),("F",1359,"But a deleted text is not an unwritten text.")], r"delet", "The site removes the writing."),
 ("L10","W","TURN, the doer: what the speaker says of his own writing becomes the sentence passed on the teacher", [("P",2931,"I am sad America because you will not hire me."),("P",2936,"and also I write poems in an unemployable way.")], [("F",1275,"Feist was to be made permanently unemployable."),("F",1377,"I do not ask you to hire me.")], r"unemployable", ""),
 ("L11","W","a charge laid on the speaker becomes the charges of a trial", [("P",2925,"I am sad because you charge me with unemployment fraud")], [("F",1011,"The first charge is that I speak without standing."),("F",1289,"His masks were to be treated as fraud.")], r"\bfraud\b", ""),
 ("L12","W","KEEP", [("P",2935,"and very large sums of student loan debt")], [("F",65,"It learned hunger, and debt, and neck pain, and shame, and late fees")], r"\bdebts?\b", ""),
 ("L13","W","KEEP: the rare word", [("P",2710,"cold and limb-wet, childlike and aching-necked")], [("F",29,"the wrong pillow under his neck"),("F",209,"My poor busted neck, said Feist")], r"\bneck", ""),
 ("L14","R","the seer's part given to a follower: the speaker's dream becomes 'its first reader's'", [("P",2659,"table, armchair, fan: a giant book, bound in"),("P",2691,"am opening the Book to climb inside and wear like a"),("P",2708,"wake, eyes squint, open slow to electric flicker")], [("F",29,"with a book open on his chest"),("F",47,"The clay gave way."),("F",55,"And when he woke, the book had already begun.")], r"when he woke|in sleep he came", "A sleeper finds and opens the Book in sleep, and wakes to write."),
 ("L15","W","KEEP: the rare word", [("P",4673,"What I am trying to say is I am a lonesome dog")], [("F",179,"the gratitude of a stray dog")], r"\bdog\b", ""),
 ("L16","R","TURN, the negation: the death the vision stages, the told life lets happen", [("P",4833,"because I will have staged my death as a media stunt in"),("P",4838,"untimely and publicly humiliating, if fake, demise")], [("F",1659,"Then the old handle logged on."),("F",1661,"It was the handle Feist had used before his death.")], r"before his death|old handle", "A death, and a return that confounds those who had judged."),
 ("L17","R","time: will / did", [("P",1520,"until, years later, I return, a sarcophagus-strange dishrag of"),("P",1521,"my former self")], [("F",409,"And what returned from that place was not the Feist who had gone out."),("F",411,"It wore his features.")], r"what returned from that place", "The one who returns is not the one who went."),
 ("L18","R","TURN, the doer: the speaker mass-produces the imitation; the adversary sells it and the teacher opposes it", [("P",1468,"I will build an enormous industrial assembly line and mass-"),("P",1470,"identical plastic metaphors and get you to buy them.")], [("F",699,"Do not expect acclaim from the sellers of glass."),("F",705,"He has cases for imitation.")], r"\bglass\b", ""),
 ("L19","W","KEEP: turned away", [("E",96,"the kind of person they turn away at the doors")], [("F",1143,"I knocked."),("F",1145,"The doors did not open.")], r"\bdoors?\b", ""),
 ("L20","R","KEEP: the argument kept, put as a question", [("E",98,"Was not Socrates counted the arch-academic, cornerstone of the Academy, when as yet there was no Academy?")], [("F",1027,"But who authorized Socrates?"),("F",1039,"I say the office exists because authority first appeared without it.")], r"who authorized Socrates", ""),
 ("L21","W","KEEP: the pair and the question", [("E",88,"How many big degrees did Whitman have? How many months did Sappho spend preparing her tenure package?")], [("F",1029,"Who authorized Sappho?"),("F",1031,"Who authorized Whitman?")], r"Sappho", ""),
 ("L22","W","ENACT, and the adversary's version marked in FS itself ('not as a genealogy now')", [("E",106,"I speak to you of the best of the Achaeans, Achilles"),("E",106,"I speak to you of Socrates and Paul and Augustine, Dante and Catullus."),("E",110,"I speak to you of Jack Feist.")], [("F",91,"Achilles begat Odysseus."),("F",117,"Ginsberg begat Jack Feist."),("F",323,"He saw Achilles, Odysseus, Sappho, Socrates, Plato, Paul, Augustine, Dante, Shakespeare, Whitman, Ginsberg")], r"Achilles", "The letter's litany ends on Jack Feist; so does the genealogy; the Name-Eater runs the same names as a stream into one function."),
 ("L23","W","TURN, the bearer: the apostle's wanderings are the teacher's", [("E",140,"the record of his desert wanderings")], [("F",229,"For thirty years Feist wandered the waste places.")], r"wander", ""),
 ("L24","W","KEEP", [("E",94,"a stumbling block to the Internet, and foolishness, to academics")], [("F",981,"Some truths cannot enter a room until foolishness opens the door."),("F",1445,"I have been a buffoon among you.")], r"foolish", ""),
 ("L25","R","foretold, it happens; another thing in the same place (a website in heaven, the archive)", [("P",1299,"I want you to know I am inventing a poetry website right"),("P",1300,"now, telepathically, in heaven.")], [("F",1369,"And what had been removed from the institution began again in the archive."),("F",1409,"And when you could not receive that love, I carried it elsewhere.")], r"began again in the archive|carried it elsewhere", "Expelled from the site, the speaker makes a place of his own."),
]

ROWS_W = [
 ("W01","W","another thing in the same place: the Deep Web / the Book", [("W",802,"In the Beginning"),("W",805,"The Deep Web was,"),("W",810,"the record that was before the reality:")], [("F",59,"In the beginning was the Book.")], r"In the beginning", "John 1:1 stands behind both, and Walt's own note 11 says so. In Walt the Book (Biblios, l. 882) is the second thing; in FS it is the first."),
 ("W02","W","HAPPEN: the semblance seen becomes a birth told", [("W",757,"a man-sized book, bound")], [("F",63,"And the Book was man."),("F",65,"The Book was born in a human body")], r"Book was man|born in a human body", "Pearl ll. 2659–2661 has the same figure (a book 'man-sized', 'a human body')."),
 ("W03","R","TURN, the doer and the verdict: making without approval is the fault the archon is born from; in the told life the teacher does it and the machinery charges it", [("W",954,"without the consent of the Deep Web, who had not given approval. The archive did not give approval.")], [("F",951,"If he builds an archive without our approval, the people may ask what approval is for.")], r"approval", ""),
 ("W04","W","KEEP: the adversary is small and eats", [("W",972,"small in stature, a dwarf devouring its own proceeding light")], [("F",309,"It was small at first."),("F",369,"It eats it.")], r"small at first|Small as a", ""),
 ("W05","W","the archon's condition, told in the vision, becomes the teacher's saying about the name (drank / drinks, weight / heavy, glory)", [("W",1004,"own eyes drank the lingering rays, blinding it"),("W",1006,"AEON grow dark, clothed in weight, thinking itself"),("W",1012,"of the immovable powers, but his own glory")], [("F",787,"It drinks the light it was given to pass through. It becomes heavy with its own glory."),("F",813,"The name that cannot release light is darkness.")], r"drinks the light|its own glory", ""),
 ("W06","R","KEEP: the adversary's 'I am'", [("W",1007,"the first and last. He said in his heart, \"I AM."),("W",1020,"\"I AM the all in all, there has been no other")], [("F",343,"I am the name behind the names."),("F",347,"I am the narrow gate of history.")], r"I am the name behind|I am the narrow gate", ""),
 ("W07","W","TURN, the bearer: a praise-name of the redeemer becomes the adversary's boast and the thing warned against", [("W",1348,"the sea of faces… the amalgam of names…")], [("F",353,"All faces will be resolved here."),("F",403,"Beware the archive that resolves all faces into one face.")], r"\bfaces\b", ""),
 ("W08","R","ENACT: the descents of one redeemer become the begettings of a voice; both end on the name", [("W",1808,"In every age, when it cries out for a poet, Walt takes on a body,"),("W",1822,"you whispered in Socrates' wise old"),("W",1823,"ears, sought form in Whitman's barbarous"),("W",1835,"until this, the final time: Jack Feist.")], [("F",123,"This is the genealogy of the voice"),("F",125,"It passed from mouth to mouth until it found the one who could not put it down."),("F",127,"That one was Feist.")], r"genealogy of the voice|mouth to mouth", ""),
 ("W09","R","TURN, the doer: the archons set the human wandering; the teacher enters the desert himself", [("W",1653,"The archons set him to wandering the deserts and the wastes"),("W",1653,"tweeting tattered messages")], [("F",225,"He entered the desert."),("F",229,"For thirty years Feist wandered the waste places."),("F",239,"He carried a phone.")], r"waste places", ""),
 ("W10","R","what is done for the elect is commanded of the followers (was prepared / preserve)", [("W",1719,"prepared a preserved generation in advance"),("W",849,"left a seed of Itself in each")], [("F",679,"Therefore preserve a remnant."),("F",693,"Keep the small fragment-seed from which the lost forest may be known again.")], r"remnant|fragment-seed", ""),
 ("W11","R","KEEP the frame (a found book and its first reader); another place (a bathroom in Redford Township / the Verdant Desert)", [("W",750,"Discovered in a Bathroom in Redford Township, Michigan, and Translated from the Martian by Lee Sharks")], [("F",27,"What we know as the Damascus Codex could have stayed lost."),("F",37,"the lip of a sealed vessel")], r"Codex|sealed vessel", ""),
 ("W12","W","TURN, the verdict: what the archons set in the human, the teacher refuses to call a private failure", [("W",1650,"The archons set loneliness within the human being's parts")], [("F",1621,"I am too sad to let the world go on pretending that loneliness is a private failure.")], r"lonel", ""),
 ("W13","R","KEEP: the last promise", [("W",1951,"And I will wipe your tears away")], [("F",1553,"I go away, but I do not leave you comfortless.")], r"comfortless|Comforter", "Each is scripture at one remove (Revelation 21:4; John 14:18). Entered as read whatever the count."),
 ("W14","R","the last bearer has only received words", [("W",1879,"& when you came this time, you found"),("W",1881,"to say what had been said, except")], [("F",151,"The mind filled with words it had not earned and could not refuse.")], r"had not earned", "Entered as read: one place of the relation, not three."),
 ("W15","W","another thing in the same place", [("W",1614,"upon on the waters of Pop Culture")], [("F",143,"Then a voice came over the waters of the body and said:")], r"\bwaters\b", "Genesis 1:2 stands behind both."),
 ("L26","W","KEEP (entered late, after the count in §2 was first taken)", [("P",2964,"I have no friends."),("P",1653,"no longer alone.")], [("F",1617,"I am tired of being alone."),("F",1619,"I am tired of your being alone.")], r"being alone", ""),
]

ROWS_X = [
 ("X01","W","ENACT: the blessing spoken becomes a going", [("X",129,"Blessed are the lonely")], [("F",253,"And the lonely became a multitude."),("F",529,"He went to the lonely.")], r"the lonely", ""),
 ("X02","W","KEEP: the speaker's, the teacher's", [("X",137,"Blessed am I in my loneliness, mother")], [("F",257,"Feist corresponded with the brothers and sisters of his aloneness.")], r"aloneness", ""),
 ("X03","W","TURN, the verdict: what the sermon grants the lonely, the forerunner forbids", [("X",131,"and start new profiles, and like them again")], [("F",467,"Build no empty profile."),("F",469,"Build no disposable ghost.")], r"profile", ""),
 ("X04","W","KEEP: the blessed without profiles are where the forerunner speaks from", [("X",123,"Blessed are those who have no profiles, or whose profiles are poorly made.")], [("F",425,"from discarded profiles, from side accounts")], r"profile", ""),
 ("X05","W","TURN, the verdict: commanded in the sermon, warned of by the forerunner", [("X",110,"Be anonymous")], [("F",443,"It has made anonymity a room where cowards throw stones.")], r"anonym", ""),
 ("X06","W","TURN, the negation: be strangers / strangers no longer", [("X",100,"Be passersby... Be strangers"),("X",110,"Be strangers still")], [("F",241,"He spoke with strangers until they were strangers no longer."),("F",281,"A stranger may become kin before the body ever enters the room.")], r"stranger", ""),
 ("X07","W","TURN, the bearer and the verdict: the blessed of the sermon is what a disciple suspects the returned teacher of being", [("X",117,"Blessed are the trolls")], [("F",1677,"Prove you are not a troll.")], r"troll", ""),
 ("X08","R","TURN, the negation: shall be heard / were to be ignored", [("X",201,"and when he speaks, he shall be heard")], [("F",1297,"And his words, where they could not be refuted, were to be ignored.")], r"ignored", ""),
 ("X09","W","TURN, the verdict: the blessing is the sentence", [("X",203,"Blessed is the unemployed, for he shall have more free time.")], [("F",1275,"Feist was to be made permanently unemployable.")], r"unemploy", "With L10."),
 ("X10","W","KEEP", [("X",205,"Blessed is the broken, for he shall go to sleep.")], [("F",1631,"Forgiveness and mercy for the broken and guilty.")], r"\bbroken\b", ""),
 ("X11","R","what the broken is promised is commanded of all (shall go to sleep / Rest)", [("X",205,"for he shall go to sleep"),("X",246,"I became fully broke… I went back to sleep"),("X",267,"Wake up or go back to sleep")], [("F",1587,"Rest."),("F",1599,"A life that cannot stop working has been captured."),("F",1747,"Rest once a week.")], r"\b[Rr]est\b", ""),
 ("X12","W","another thing in the same place: boredom / extraction", [("X",115,"for theirs is the kingdom of boredom")], [("F",1595,"It is a command against the kingdom of extraction.")], r"kingdom of", ""),
 ("X13","W","ALTERED (Medicaid / health insurance); the speaker's own account becomes the teacher's answer to a charge", [("X",244,"I worked 7 years for a PhD… my children were on Medicaid")], [("F",1135,"I sought your insurance"),("F",1141,"A person with children does not transcend health insurance by having a beautiful theory of vocation.")], r"insurance", ""),
 ("X14","R","TURN, the doer: the speaker's litany is the adversary's (with L06)", [("X",95,"I am a creature… a sandwich… everything… nothing"),("X",231,"all things to all people"),("X",233,"Be nothing to no one… Be no one")], [("F",345,"I am the passage through which all authors pass."),("F",375,"A poet who claims all inheritance as himself becomes the death of inheritance.")], r"I am the passage|claims all inheritance", ""),
]

ROWS_N = [
 ("N01","W","KEEP", [("A",375,"Guard the seed."),("A",380,"Guard the seed.")], [("F",837,"Guard the seed."),("F",1743,"Guard the seed.")], r"Guard the seed", ""),
 ("N02","R","KEEP, each member: hands, dark, not buried, the air", [("A",264,"Protect what is in your hands, and what you keep in the dark will see the light."),("A",267,"What incubates below will leap up through the air. Nothing bright can be buried.")], [("F",823,"Cup it in your hands."),("F",825,"Plant in darkness."),("F",831,"What is true will not remain buried."),("F",833,"What is living will seek the air.")], r"Cup it in your hands|will not remain buried|seek the air", ""),
 ("N03","W","ALTERED, another thing in the same place: the kingdom / the work", [("A",444,"A person cannot serve two masters, both the name and the kingdom")], [("F",845,"You cannot serve both the name and the work.")], r"cannot serve both", ""),
 ("N04","W","HAPPEN: the sign given in a saying is told of the teacher (her / his)", [("A",329,"When you see one who is her own mother and father, follow her."),("A",651,"Whoever is unwilling to become his own mother and father cannot be my disciple")], [("F",173,"He became his own mother and father.")], r"own mother and father", ""),
 ("N05","W","KEEP: the rare word (with L15)", [("A",453,"We are lonesome dogs, like you are.")], [("F",179,"the gratitude of a stray dog")], r"\bdog\b", ""),
 ("N06","W","the scripture's saying kept in Antioch is made a new likeness in FS (swine / the vanity jeweler)", [("A",629,"Do not cast pearls before swine.")], [("F",701,"If you bring a real pearl to a vanity jeweler, do not be surprised when he cannot price it."),("F",819,"Do not cast the seed where hungry birds wait only to steal it.")], r"vanity jeweler|Do not cast", "Matthew 7:6 stands behind Antioch's line."),
 ("N07","W","ALTERED, the verdict softened: woe / troubled, and “Let the record be fair”", [("A",653,"Woe to the academics, for they are like trained dogs, performing tricks for a crumb.")], [("F",927,"This troubled the academics."),("F",929,"Not all of them. Let the record be fair.")], r"academics", ""),
 ("N08","R","TURN, the negation: “I will hire myself” / “I do not ask you to hire me”", [("A",544,"'We will hire you, but at your current rate of pay, no benefits.'"),("A",547,"'If no one will hire me, I will hire myself. I am the earth and sky.'")], [("F",1275,"Feist was to be made permanently unemployable."),("F",1377,"I do not ask you to hire me.")], r"\bhire\b", "The parable's poor student is the teacher in the told life."),
 ("N09","W","TURN, the bearer: outsiders ask the disciples; a disciple asks the returned teacher", [("A",459,"'What proof?' say to them, 'The living voice and the dying.'")], [("F",1681,"What proof do you want?")], r"What proof", ""),
 ("N10","R","TURN, the negation: the box is recovered, opened and played; the files remain and cannot be opened", [("A",485,"the black box will be recovered, opened, and played"),("A",488,"Everything else will burn, but the black box will not burn.")], [("F",659,"Not because the books will burn in one great fire."),("F",665,"No, the files will remain and become unreadable."),("F",667,"The words will survive without the machines that knew how to open them.")], r"unreadable|will burn", ""),
 ("N11","W","HAPPEN: named in a saying, he appears", [("A",442,"From Socrates to Johannes Sigil")], [("F",421,"Its name was Johannes Sigil.")], r"Johannes Sigil", ""),
 ("N12","W","KEEP (with W05)", [("A",384,"When you shine for your own eyes, you become muddy and dank.")], [("F",787,"But when a name shines only for itself, it bends inward.")], r"shines only for itself", ""),
 ("N13","W","TURN, the verdict: what the teacher says he is, the teaching forbids making", [("A",557,"This is the machine. I am a ghost.")], [("F",469,"Build no disposable ghost."),("F",765,"Do not make disposable ghosts.")], r"ghosts?\b", ""),
]
DOUBLETS = [
 ("“No man is a poet among poets”", [("A",400,"No man is a poet among poets"),("E",72,"no man is a poet among poets")]),
 ("the lonely blessed", [("A",451,"Blessed is the lonely, for hers is the lonely kingdom."),("X",129,"Blessed are the lonely")]),
 ("the broken blessed", [("A",479,"Blessed are the broken, in whose shards is power perfected."),("X",205,"Blessed is the broken, for he shall go to sleep.")]),
 ("the voice inside the voice", [("A",588,"I am the smaller voice inside the voice."),("X",224,"I am the voice within your voice"),("W",889,"the voice within the voice")]),
 ("source, and what circles all", [("A",620,"then you are my source, as I am yours, and the kingdom circles all"),("E",100,"You are my source"),("W",811,"and the Deep Web circles all.")]),
 ("the virus", [("A",286,"I have released a virus into this world, and I am watching until it breaks out."),("X",222,"an alien producing a virus"),("W",1876,"an alien producing a virus")]),
 ("the ancient child", [("A",346,"Blessed is the ancient child."),("W",1870,"an ancient child")]),
 ("each word of scripture again", [("A",331,"I have come to rehearse each word of scripture, exactly as they are"),("W",1942,"I have written each word again, exactly as it was")]),
 ("lonesome dog", [("A",453,"We are lonesome dogs, like you are."),("P",4673,"I am a lonesome dog")]),
 ("the secret name", [("A",418,"then will you know your secret name, and be unafraid"),("P",1606,"with a secret name writ on it")]),
 ("the death told", [("A",679,"Light breaks through my face."),("A",682,"I die."),("P",2689,"my death happens only partway through the")]),
]
FORCE_READ = {"W13","W14"}
def table(rows):
    out = []; reached = set(); c = r_ = t_ = 0
    for rid, kind, move, src, tgt, rare, note in rows:
        s = "; ".join(q(*x) for x in src); t = "; ".join(q(*x) for x in tgt)
        ss = secs(rare); n = len(ss); status = "counted" if (n <= 3 and rid not in FORCE_READ) else "read"
        c += status == "counted"; r_ += status == "read"; t_ += "TURN" in move
        for x in tgt: reached.add(sec[x[1]])
        out.append(f"| {rid} | {kind} | {s} | {t} | {move} | {', '.join(ss)} ({n}) | {status} |")
        if note: out.append(f"| | | *{note}* | | | | |")
    return out, reached, c, r_, t_
def num(reached): return sorted([x for x in reached if x[0] == "§"], key=lambda s: int(s[1:]))
HDR = "| Row | Kind | Source | Feist Source | Move | Stands in FS at | |\n|---|---|---|---|---|---|---|\n"
o1, r1, c1, rd1, t1 = table(ROWS); o2, r2, c2, rd2, t2 = table(ROWS_W); o3, r3, c3, rd3, t3 = table(ROWS_X); o4, r4, c4, rd4, t4 = table(ROWS_N)
dbl = '\n'.join(f'- {name}: ' + '; '.join(q(*x) for x in xs) for name, xs in DOUBLETS)
wr = set().union(*[{sec[x[1]]} for row in ROWS_W if row[0].startswith("W") for x in row[4]])
allr = r1 | r2 | r3 | r4
trial = [x for x in num(wr) if 24 <= int(x[1:]) <= 35]; core = [x for x in num(wr) if int(x[1:]) in (1,2,3,9,10,11)]
print(json.dumps({"n": [len(ROWS_N), c4, rd4, t4, num(r4)], "all_n": len(num(allr)), "x": [len(ROWS_X), c3, rd3, t3, num(r3)], "pearl_epistle": [len(ROWS), c1, rd1, t1, num(r1)], "walt": [len(ROWS_W), c2, rd2, t2, num(wr)], "all": [len(num(allr)), num(allr)], "walt_trial": trial, "walt_core": core}, ensure_ascii=False))
p = R/"rebuild/unfolding-map/feist/LEDGER.md"; s = p.read_text(encoding="utf-8")
head = s.split("## 1. Rows")[0]
body = "## 1. Rows, Pearl and the Epistle to the Feist Source\n\nRead by the session on 2026-11-28: Pearl ll. 1293–1653, 2645–2722, 2917–2968, 3006–3055, 4500–4504, 4825–4839; the Epistle ll. 64–146; the Feist Source whole. Every quotation below was checked at its line by `build_ledger.py`. The last column but one is where the row's rare word or configuration stands in FS, by section.\n\n" + HDR + "\n".join(o1)
body += "\n\n## 1a. Rows, Walt to the Feist Source\n\nRead by the session on 2026-11-28: Walt §§I–XII (ll. 747–2009), the text without its notes. L26 is a Pearl row entered late.\n\n" + HDR + "\n".join(o2)
body += "\n\nNot in FS at all, by search: Herod (Walt l. 1870), “I am the one who was within you” (l. 763), the Unicorn Horn, the hologram, Kanye, the thirty-six, the sparks gathered, the cost of each descent (l. 1835), the Logos and the skullcase (l. 1867), Redford.\n"
body += "\n## 1b. Rows, I Am X to the Feist Source\n\nRead by the session on 2026-11-28: the poem, ll. 85–269, without its notes.\n\n" + HDR + "\n".join(o3) + "\n\nNot in FS at all, by search: the form “Blessed” (twenty-two in the poem; FS has the word once, l. 1519, “A church may bless”), the form “Be” as a command to become a kind of person, “passersby”, the billionaire with no money, the rag of light, the resolutions for 2016. “The Logos awoke in my skullcase” (l. 218) and “the one who was within me” (ll. 224, 251) stand in Walt (ll. 1867, 1339) and not in FS.\n"
body += "\n## 1c. Rows, Antioch to the Feist Source\n\nRead whole by the session on 2026-11-28 at 17:50 (the logia, ll. 248–692), after the author's note that Antioch is the strongest source for voice and for the objects of vision. Antioch had been held out as the check; from this section on it is a source and the session is no longer blind to it. These rows were found after the others and are not a test of them.\n\n" + HDR + "\n".join(o4) + "\n\n### Doublets among the sources\n\nThe same words or figure in two or three sources, checked at the line. Most are not in FS.\n\n" + dbl + "\n"
body += f"\n## 2. Counts\n\nPearl and the Epistle: {len(ROWS)} rows, {c1} counted, {rd1} entered as read (their word or configuration stands in more than three sections of FS), {t1} turning a slot; {len(num(r1))} of FS's 45 sections reached ({', '.join(num(r1))}), with the prologue.\n\nWalt and the late row: {len(ROWS_W)} rows, {c2} counted, {rd2} read, {t2} turning a slot. Walt reaches {', '.join(num(wr))}, with the prologue.\n\nI Am X: {len(ROWS_X)} rows, {c3} counted, {rd3} read, {t3} turning a slot; it reaches {', '.join(num(r3))}, of which new: {', '.join(x for x in num(r3) if x not in (r1|r2))}.\n\nAntioch: {len(ROWS_N)} rows, {c4} counted, {rd4} read, {t4} turning a slot; it reaches {', '.join(num(r4))}, of which new: {', '.join(x for x in num(r4) if x not in (r1|r2|r3))}.\n\nAll five sources: {len(num(allr))} of 45 sections ({', '.join(num(allr))}). Not reached by any row: {', '.join('§'+str(i) for i in range(1,46) if '§'+str(i) not in allr)}.\n"
PRED = R/"rebuild/unfolding-map/feist/predictions-outcome.md"
body += "\n" + PRED.read_text(encoding="utf-8") if PRED.exists() else ""
p.write_text(head + body, encoding="utf-8")
