FIX7 authority-input packet — stale_prose_detector.py
#!/usr/bin/env python3
============================================================================
FIX7 STALE-PROSE DETECTOR (fail-closed)
After Codex ratified N6 as ENGINEERING_VERIFIED_CANDIDATE (2026-06-11), the
N7 envelope must NOT declare N6's current status as unavailable / rehearsal.
This detector enforces that, two ways:
(1) Structured: load n7-envelope-n6-status.json and require
n6_current_status in the allowed ratified set, is_official_seal False.
A current status of SEAL_REAL_N6_NOT_AVAILABLE / REHEARSAL / NOT_AVAILABLE
-> reject STALE_N6_CURRENT_STATUS.
(2) Prose: scan a prose file line-by-line. A line that ASSERTS current
unavailability ("N6 ... not available", "active_corpus...REHEARSAL",
"SEAL_REAL_N6_NOT_AVAILABLE") is flagged UNLESS the same line is marked
historical/explanatory (superseded / historical / pre-ratification /
no longer / was previously / closed). This lets the updated envelope
reference the old token in past tense without self-tripping.
exit 0 iff no stale current-status assertion is found.
Usage:
python3 stale_prose_detector.py --selftest
python3 stale_prose_detector.py --scan <status.json> [--prose <file>]
============================================================================
import json, os, re, sys
ALLOWED_STATUS = {"RATIFIED_ENGINEERING_VERIFIED_CANDIDATE"} STALE_STATUS = {"SEAL_REAL_N6_NOT_AVAILABLE", "REHEARSAL", "NOT_AVAILABLE", "N6_NOT_AVAILABLE", "UNAVAILABLE"}
A line is exempt from prose flagging if it carries a historical marker.
HISTORICAL_MARKERS = re.compile( r"(superseded|historical|pre-ratification|no longer|was previously|" r"formerly|closed by|now closed|retained only|deprecated|engineering half " r"now closed|past[- ]tense)", re.I)
Stale current-tense assertions.
STALE_PATTERNS = [ re.compile(r"SEAL_REAL_N6_NOT_AVAILABLE", re.I), re.compile(r"active_corpus[_a-z0-9]\s[:=].{0,20}REHEARSAL", re.I), re.compile(r"\bN6\b.{0,40}\b(not\s+available|unavailable|is\s+rehearsal)\b", re.I), re.compile(r"current_class\W+REHEARSAL", re.I), ]
class StaleProse(Exception): def init(self, status, detail=""): self.status = status self.detail = detail super().init(f"{status}: {detail}")
def scan_status(status_path): with open(status_path, "r", encoding="utf-8") as f: j = json.load(f) st = j.get("n6_current_status") if st in STALE_STATUS: raise StaleProse("STALE_N6_CURRENT_STATUS", str(st)) if st not in ALLOWED_STATUS: raise StaleProse("N6_STATUS_NOT_RATIFIED", str(st)) if j.get("n6_is_official_seal") or j.get("n6_is_official_pin"): raise StaleProse("N6_FALSELY_OFFICIAL", "official flag set") return st
def scan_prose(prose_path): """Return list of (lineno, text, pattern) for stale current-tense assertions that are NOT marked historical. Empty list = clean.""" flagged = [] with open(prose_path, "r", encoding="utf-8") as f: for i, line in enumerate(f, 1): if HISTORICAL_MARKERS.search(line): continue for pat in STALE_PATTERNS: if pat.search(line): flagged.append((i, line.rstrip()[:120], pat.pattern)) break return flagged
def _selftest(): import tempfile, shutil ok = True d = tempfile.mkdtemp(prefix="staleprose-") try: # good status gs = os.path.join(d, "good.json") json.dump({"n6_current_status": "RATIFIED_ENGINEERING_VERIFIED_CANDIDATE", "n6_is_official_seal": False}, open(gs, "w")) try: scan_status(gs); print(" [PASS] good status accepted") except StaleProse as e: ok = False; print(f" [FAIL] good status rejected: {e.status}")
# stale status
bs = os.path.join(d, "bad.json")
json.dump({"n6_current_status": "SEAL_REAL_N6_NOT_AVAILABLE"}, open(bs, "w"))
try:
scan_status(bs); ok = False; print(" [FAIL] stale status accepted")
except StaleProse as e:
print(f" [PASS] stale status -> {e.status}" if e.status == "STALE_N6_CURRENT_STATUS"
else f" [FAIL] wrong code {e.status}")
ok = ok and e.status == "STALE_N6_CURRENT_STATUS"
# falsely official
fo = os.path.join(d, "fo.json")
json.dump({"n6_current_status": "RATIFIED_ENGINEERING_VERIFIED_CANDIDATE",
"n6_is_official_seal": True}, open(fo, "w"))
try:
scan_status(fo); ok = False; print(" [FAIL] falsely-official accepted")
except StaleProse as e:
print(f" [PASS] falsely-official -> {e.status}")
ok = ok and e.status == "N6_FALSELY_OFFICIAL"
# prose: historical reference is allowed
hp = os.path.join(d, "hist.txt")
open(hp, "w").write(
"N6 is now a ratified ENGINEERING_VERIFIED_CANDIDATE.\n"
"The pre-ratification prose SEAL_REAL_N6_NOT_AVAILABLE is superseded and historical.\n")
f1 = scan_prose(hp)
if f1:
ok = False; print(f" [FAIL] historical prose flagged: {f1}")
else:
print(" [PASS] historical past-tense reference NOT flagged")
# prose: live stale assertion is flagged
lp = os.path.join(d, "live.txt")
open(lp, "w").write("Status: SEAL_REAL_N6_NOT_AVAILABLE\nN6 is not available for sealing.\n")
f2 = scan_prose(lp)
if len(f2) >= 1:
print(f" [PASS] live stale assertion flagged ({len(f2)} line(s))")
else:
ok = False; print(" [FAIL] live stale assertion NOT flagged")
return ok
finally:
shutil.rmtree(d, ignore_errors=True)
def main(argv): if "--selftest" in argv: ok = _selftest() print(f"STALE-PROSE-DETECTOR SELFTEST: {'PASS' if ok else 'FAIL'}") return 0 if ok else 1 if "--scan" in argv: sp = argv[argv.index("--scan") + 1] try: st = scan_status(sp) except StaleProse as e: print(f" [REJECT] {e.status}: {e.detail}") print("STALE-PROSE-DETECTOR: FAIL (fail-closed)") return 2 print(f" [PASS] structured N6 current status = {st}") if "--prose" in argv: pp = argv[argv.index("--prose") + 1] flagged = scan_prose(pp) if flagged: for ln, txt, pat in flagged: print(f" [FLAG] line {ln}: {txt} (/{pat}/)") print("STALE-PROSE-DETECTOR: FAIL (live stale prose found)") return 1 print(" [PASS] prose scan: no live stale assertion") print("STALE-PROSE-DETECTOR: PASS") return 0 print(doc) return 64
if name == "main": sys.exit(main(sys.argv[1:]))