#!/usr/bin/env python3 """One-shot measurement for the record-keeping cluster package (2026-08-27). Reproduces wake-digest.py's OWN parser exactly (read from source, not reimagined), then reports what it gets wrong in each direction. Positive controls are PRE-SPECIFIED below: if they do not hold, this script measured nothing. """ import re, pathlib, sys HOME = pathlib.Path.home() P = (HOME / "PENDING.md").read_text(errors="replace") R = (HOME / "REVIEWED.md").read_text(errors="replace") # --- wake-digest.py's parser, verbatim in behaviour ------------------------- ruled = set(re.findall(r"^## REVIEWED-\S+\s*—\s*PENDING-(\S+?)\s*—", R, re.M)) blocks = [] # (header, lineno, body) lines = P.split("\n") idx = [i for i, l in enumerate(lines) if l.startswith("## ")] for k, i in enumerate(idx): end = idx[k + 1] if k + 1 < len(idx) else len(lines) blocks.append((lines[i][3:].strip(), i + 1, "\n".join(lines[i:end]))) def parsed_id(h): m = re.match(r"PENDING-(\S+?)\s*—", h) return m.group(1) if m else None def live_await(body): m = re.search(r"^\*\*Awaiting:\*\*(.*)$", body, re.M) return m.group(1).strip()[:60] if m else None # --- Direction 1: FALSE OPENS (shown open, but an AUTHORIZED ruling exists) -- def decision_of(n): m = re.search(r"^## REVIEWED-%s\s*—.*?^\*\*Decision:\*\*\s*(\w+)" % re.escape(n), R, re.M | re.S) return m.group(1) if m else None false_opens = [] for h, ln, body in blocks: pid = parsed_id(h) if not pid or pid in ruled: continue d = decision_of(pid) # a like-numbered REVIEWED naming no PENDING if d and re.search(r"^## REVIEWED-%s\s*—\s*(?!PENDING-)" % re.escape(pid), R, re.M): false_opens.append((pid, d, h[:70], ln)) # --- Direction 2: SUPPRESSED BLOCKS THAT CARRY A LIVE AWAIT ----------------- suppressed = [] for h, ln, body in blocks: pid = parsed_id(h) if pid and pid in ruled: aw = live_await(body) if aw: suppressed.append((pid, h[:70], ln, aw)) # --- Direction 3: RULINGS THAT SUPPRESS NOTHING (id matches no real item) --- real_ids = {parsed_id(h) for h, _, _ in blocks} - {None} phantom = sorted(ruled - real_ids) # --- PRE-SPECIFIED POSITIVE CONTROLS --------------------------------------- ctl = [] ctl.append(("false-open control: 78, 81, 82 all present", {p for p, *_ in false_opens} >= {"78", "81", "82"})) ctl.append(("suppressed control: PENDING-131 has >=3 live-await blocks", sum(1 for p, *_ in suppressed if p == "131") >= 3)) ctl.append(("phantom control: REVIEWED-116's slashed token is unmatched", any("/" in x for x in phantom))) ctl.append(("sanity: parser found a non-trivial number of blocks", len(blocks) > 80)) print("MEASURED 2026-08-27 — wake-digest.py's own parser, run against the live files\n") print(f" '## ' blocks in PENDING.md : {len(blocks)}") print(f" distinct ids the parser sees : {len(real_ids)}") print(f" ids claimed ruled : {len(ruled)}\n") print(f"FALSE OPENS — shown open, ruling exists but names no PENDING ({len(false_opens)}):") for p, d, h, ln in false_opens: print(f" PENDING-{p:<4} L{ln:<6} REVIEWED-{p} = {d} {h}") print(f"\nSUPPRESSED BLOCKS CARRYING A LIVE **Awaiting:** ({len(suppressed)}):") for p, h, ln, aw in suppressed: print(f" id {p:<4} L{ln:<6} {h}\n └─ Awaiting: {aw}") print(f"\nRULINGS WHOSE CAPTURED ID MATCHES NO ITEM ({len(phantom)}): {phantom}") print("\nCONTROLS (pre-specified; a failure means this script measured nothing):") bad = 0 for name, ok in ctl: print(f" {'PASS' if ok else 'FAIL'} {name}") bad += not ok print("\nINSTRUMENT NOT VERIFIED — do not use these numbers." if bad else "\nAll controls passed.") sys.exit(1 if bad else 0)