#!/usr/bin/env python3 """public_copy — the PUBLIC pre-registration, cut from the sealed file BY CODE. python3 harness/public_copy.py --write # regenerate prereg/PREREG-TWO-FRONTIERS-public.md python3 harness/public_copy.py --check # refuse if the file on disk is not what this writes PREREG A4.3 registers three substitutions and nothing else: the co-signer's name reads "an operator", the production port number and home-directory paths are DESCRIBED rather than printed. PREREG A16 (6) registers this file, for a measured reason: the kit's copy of the prereg was cut BY HAND at A4 and never re-cut, so a kit that says "the pre-registration, frozen before the first scored call" shipped three of sixteen amendments. A hand-cut copy of a growing document is a copy that goes stale silently. This one is a function of the sealed file. WHAT THIS FILE WILL NOT DO -------------------------- It never stores the co-signer's name. The name is read out of the sealed file's own title line at run time — the token in ``(, 2026-09-05`` — and used only as the left side of a substitution, so nothing tracked in this repo carries it and nothing this module prints can. The same discipline covers the port: it is read from the roster's local-arm ``base_url``, which is where the round registered it, rather than typed here. THE FOURTH THING, WHICH IS NOT A SUBSTITUTION -------------------------------------------- The public copy also carries an opening italic paragraph naming the substitutions. It is not a redaction; it is the copy telling a reader what was changed, which is the only thing that makes the sealed sha beside it worth anything. Its bytes are frozen: the freeze index recorded the first cut's sha256, and `test_a16_kit.py` asserts this code still reproduces it for the region that cut covered. """ from __future__ import annotations import sys sys.dont_write_bytecode = True import argparse import hashlib import json import re from pathlib import Path BASE = Path(__file__).resolve().parent.parent SEALED_PATH = BASE / "prereg" / "PREREG-TWO-FRONTIERS.md" PUBLIC_PATH = BASE / "prereg" / "PREREG-TWO-FRONTIERS-public.md" ROSTER_PATH = BASE / "prereg" / "rosters.json" #: The co-signer's name is READ, never stored: the sealed title line ends `(, 2026-09-05 ...`. TITLE_NAME_RE = re.compile(r"\(([A-Za-z0-9_.\-]{2,40}), 20\d\d-\d\d-\d\d") #: A4.3 (a). The document refers to the co-signer by name and, in §10 and §12, as "an operator"; #: both read "an operator" in the public copy, which is also the house's own voice law for a #: published page — never "an operator". CO_SIGNER = "an operator" THE_OPERATOR_RE = re.compile(r"\b(?P[Tt]he) operator\b") #: A4.3 (b). The phrase is the first cut's own, and the freeze index's sha pins it. PORT_DESCRIPTION = "the seat's own port" #: A19 (5). Any other production port the sealed text prints, in the same shape: a backticked or #: bare `:NNNNN` that does not follow a word character and does not start with 0 (a pinned model #: tag variant such as `:0813` is not a port, whether glued to its tag or quoted bare). OTHER_PORT_RE = re.compile(r"(? str: """The name token, from the sealed file's own title line. Read at run time, never stored.""" first = sealed_text.splitlines()[0] if sealed_text else "" match = TITLE_NAME_RE.search(first) if not match: raise SystemExit( "the title line does not carry the co-signer token in the registered shape " "`(, `, so this cut cannot know what to substitute. PREREG A4.3 (a) is not " "something to guess at: fix the title line or the pattern, never the output. (An " "already-cut PUBLIC copy has no token left, and this refusal is what stops a cut of a " "cut: the source is the SEALED file, always.)" ) return match.group(1) def production_port(roster_path: Path | None = None) -> str: """The production instance's port, from the roster's own local-arm endpoint (PREREG A2). Read rather than typed, for the same reason every other number in this round is read: the roster is the registered artifact, its sha256 is in the freeze index, and a port typed into a scorer is a second place for it to be wrong. """ roster = json.loads((roster_path or ROSTER_PATH).read_text(encoding="utf-8")) local = [a for a in roster.get("arms", []) if a.get("transport_class") == "local-ollama"] ports = {m.group(1) for a in local for m in [re.search(r":(\d{2,5})/?$", str(a.get("base_url") or ""))] if m} if len(ports) != 1: raise SystemExit( f"the roster names {len(ports)} distinct local-arm ports {sorted(ports)}; PREREG A4.3 " "(b) describes THE production port, and a cut that guessed which one would publish the " "other." ) return ports.pop() def public_prereg(sealed_text: str, *, port: str | None = None) -> str: """The sealed text with A4.3's three substitutions applied, and nothing else. The order is deliberate: the name goes first (so a "an operator" created by nothing else is the document's own phrasing), then the port, then the paths. This is NOT idempotent, deliberately: an already-cut copy has no co-signer token in its title line, so feeding one back in REFUSES rather than quietly re-cutting. The source is the sealed file, always. """ token = co_signer_token(sealed_text) text = sealed_text # (a) the co-signer, by name and by role for variant in dict.fromkeys((token, token.lower(), token.upper(), token.capitalize())): text = text.replace(variant, CO_SIGNER) text = THE_OPERATOR_RE.sub( lambda m: ("An" if m.group("the")[0] == "T" else "an") + " operator", text) # (b) the production port, in every shape the document writes it: backticked, colon-prefixed, # or bare. The number itself is never written here — it comes from the roster. port = port or production_port() text = re.compile(r"`?:?" + re.escape(port) + r"`?").sub(PORT_DESCRIPTION, text) # PREREG A19 (5): the sealed text names a SECOND production instance by its port, in the same # backticked `:NNNNN` shape. The first cut described one port and printed the other. Every # remaining port-shaped literal — a colon and four or five digits not glued to a word character # (a model tag such as `deepseek-v4-pro:0813` is not a port) — is described the same way, and # the number is never written in this file. text = OTHER_PORT_RE.sub(OTHER_PORT_DESCRIPTION, text) left = OTHER_PORT_RE.findall(text) if left: raise SystemExit(f"public_copy: {len(left)} port-shaped literal(s) survive the cut; refusing " "to write a public copy that prints a port.") # (c) home-directory paths text = HOME_PATH_RE.sub(HOME_PATH_DESCRIPTION, text) # and the paragraph that says so, after the title line and its blank lines = text.split("\n") return "\n".join(lines[:1] + ["", OPENING_PARAGRAPH] + lines[1:]) #: A top-level amendment bullet. Its sub-bullets are indented and belong to the amendment above. AMENDMENT_BULLET_RE = re.compile(r"^- \*\*(A\d+) ·") def region_through(text: str, *, last_amendment: str) -> str: """The prefix of a cut copy through ``last_amendment`` AND its indented sub-bullets. The first hand cut ended at A3, so the byte-identity assertion needs the same slice of this one — and A3 carries three sub-bullets, which are part of A3 and not of A4. The slice therefore ends at the next TOP-LEVEL amendment bullet, not at the named one's own line. """ lines = text.split("\n") start = next((i for i, line in enumerate(lines) if line.startswith(f"- **{last_amendment} ·")), None) if start is None: raise SystemExit(f"no amendment bullet for {last_amendment!r} in this copy") end = next((j for j in range(start + 1, len(lines)) if AMENDMENT_BULLET_RE.match(lines[j])), len(lines)) return "\n".join(lines[:end]).rstrip("\n") + "\n" def amendments_in(text: str) -> list[str]: """Every amendment id the copy carries, in document order.""" return re.findall(r"^- \*\*(A\d+) ·", text, flags=re.MULTILINE) def cut(*, sealed_path: Path | None = None) -> str: return public_prereg((sealed_path or SEALED_PATH).read_text(encoding="utf-8")) def main(argv: list[str] | None = None) -> int: ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) ap.add_argument("--write", action="store_true") ap.add_argument("--check", action="store_true") ap.add_argument("--sealed", default=None) ap.add_argument("--out", default=None) args = ap.parse_args(argv) text = cut(sealed_path=Path(args.sealed) if args.sealed else None) out = Path(args.out) if args.out else PUBLIC_PATH ids = amendments_in(text) sha = hashlib.sha256(text.encode("utf-8")).hexdigest() if args.write: out.write_text(text, encoding="utf-8") print(f"wrote {out} · {len(ids)} amendments ({ids[0]}…{ids[-1]}) · sha256 {sha}") return 0 if args.check: on_disk = out.read_text(encoding="utf-8") if out.is_file() else None if on_disk == text: print(f"{out.name}: matches the cut · {len(ids)} amendments · sha256 {sha[:12]}…") return 0 print(f"{out.name}: DISAGREES with the cut this code makes (sha256 {sha[:12]}… expected). " "A public copy that is not a function of the sealed file is a hand-cut copy again.") return 4 print("public_copy — plan only, nothing written") print(f" sealed {SEALED_PATH.name}") print(f" public {out.name}") print(f" substitutions: the co-signer → {CO_SIGNER!r} · the production port → " f"{PORT_DESCRIPTION!r} · home-directory paths → {HOME_PATH_DESCRIPTION!r}") print(f" amendments in the cut: {len(ids)} ({ids[0]}…{ids[-1]})") print("TOTALS 0 calls made by this file") return 0 if __name__ == "__main__": raise SystemExit(main())