#!/usr/bin/env python3 """Lane SD: read `shim.airng.txt` and print the composer rows next to the turn bracket they sit in. Usage: parse_aidesign.py [...] Prints, per run: * the arming lines, because an absent `aidesign` row and a hook that never armed look identical (method rule 20, and lane L3's `hooks=off watch=on` that reported a confident zero); * one line per AI turn bracket with its word total; * one line per composer call with the cost model's prediction beside the measurement; * a footer that checks the two arithmetic identities the run must satisfy: sum(composer sub_words) <= the bracket's left_delta, with the split reported, and words == sub_words on every composer row (the two independent measurements). """ import re import sys import os ARM = re.compile(r"^(airng|aidesign): ") BR = re.compile(r"^airng seq=(\d+) pid=(\d+) agent=(\S+) .*left_delta=(\d+) observed=(\d+) " r"calls=(\d+) residual=(-?\d+) foreign_words=(\d+)") DES = re.compile(r"^aidesign seq=(\d+) dseq=(\d+) rc=(-?\d+) dry=(\d+) size=(-?\d+) budget=(\S+) " r"role=(-?\d+) flags=(\S+) words=(\d+) sub_words=(\d+) left=(-?\d+)->(-?\d+) " r"N=(\d+) q=(\d+)/(\d+)/(\d+) pd=(\d)(\d)(\d) f=(\S+) M=(-?\d+) D=(-?\d+) " r"H_pred=(\d+) H_obs=(\d+) model=(\S+)") SITE = re.compile(r"^aidesignsite seq=(\d+) dseq=(\d+) (.*)$") PART = re.compile(r"^aidesignpart seq=(\d+) dseq=(\d+) part=(\d+) sec=(\S+) mounts=(\d+) " r"qual=(\d+) pd=(\d) name=(.*)$") CALL = re.compile(r"^airngcall seq=(\d+) pid=(\d+) ret_rva=\S+ va=(\S+) facade=(\S+) calls=(\d+)" r"(?: trues=(\d+))?") def one(path): txt = open(path, encoding="utf-8", errors="replace").read().splitlines() print(f"===== {path}") armed = False for ln in txt: if ARM.match(ln): print(" " + ln) if ln.startswith("aidesign: composer") and "create=MH_OK enable=MH_OK" in ln: armed = True print(f" ARMED: {'yes' if armed else 'NO -- every zero below is void'}") bracket_words = {} des_by_seq = {} for ln in txt: m = BR.match(ln) if m: seq, pid, agent, delta, obs, calls, resid, foreign = m.groups() bracket_words[seq] = int(delta) print(f" bracket seq={seq} pid={pid} agent={agent} words={delta} observed={obs} " f"residual={resid} foreign={foreign}") continue m = DES.match(ln) if m: g = m.groups() des_by_seq.setdefault(g[0], []).append(g) print(f" composer dseq={g[1]} rc={g[2]} dry={g[3]} size={g[4]} flags={g[7]} " f"words={g[8]}/{g[9]} N={g[12]} q={g[13]}/{g[14]}/{g[15]} " f"pd={g[16]}{g[17]}{g[18]} f={g[19]} M={g[20]} D={g[21]} " f"H_pred={g[22]} H_obs={g[23]} {g[24]}") continue m = SITE.match(ln) if m: print(f" sites dseq={m.group(2)} {m.group(3)}") continue m = PART.match(ln) if m: g = m.groups() if g[3] != "0x00000000": print(f" part {g[2]} sec={g[3]} mounts={g[4]} qual={g[5]} pd={g[6]} {g[7]}") continue m = CALL.match(ln) if m: print(f" facade seq={m.group(1)} {m.group(3)} {m.group(4)} calls={m.group(5)} " f"trues={m.group(6)}") # ---- the two identities ---------------------------------------------------------------- bad = 0 for seq, rows in des_by_seq.items(): total = sum(int(r[9]) for r in rows) if seq in bracket_words: out = bracket_words[seq] - total if out < 0: print(f" ! seq={seq}: composer sub_words {total} EXCEEDS bracket words " f"{bracket_words[seq]} -- the sub-bracket is double counting") bad += 1 else: # Not an error: on a deeper board the AI also draws in the task system and the # research pick. The split is the number worth reading. print(f" seq={seq}: {total} of {bracket_words[seq]} words in the composer, " f"{out} outside it") for r in rows: if r[8] != r[9]: print(f" ! seq={seq} dseq={r[1]}: words={r[8]} != sub_words={r[9]} " f"-- the two measurements disagree") bad += 1 print(f" identities: {'OK' if bad == 0 else str(bad) + ' FAILED'}") def main(): for a in sys.argv[1:]: if os.path.isdir(a): one(os.path.join(a, "shim.airng.txt")) else: one(a) if __name__ == "__main__": main()