diff --git a/wizard-work/forge/R41_REFACTOR_PIXELDIFF_VERIFICATION.md b/wizard-work/forge/R41_REFACTOR_PIXELDIFF_VERIFICATION.md new file mode 100644 index 0000000..dbd2b97 --- /dev/null +++ b/wizard-work/forge/R41_REFACTOR_PIXELDIFF_VERIFICATION.md @@ -0,0 +1,77 @@ +# R41 Refactor — Pixel-Diff Verification + +Artifact: `verify_r41_pixel_diff.py` +Lane: Refactor (behaviour-preserving DRY extraction) +Verdict: PASS — refactored r41 card is pixel-for-pixel identical to the original. + +## What was being verified + +`/root/.hermes/ops-pulse-card-r41.py` is an original, inline-PIL ops-pulse card +(tick `2026-10-15 20:59Z`, "Sentinel onboarded; model claim verified"). The +refactor delegates all PIL boilerplate to the shared +`ops_pulse_card_lib.render_card()` so the card reduces to a single +`CardParams(...)` + `render_card(params)` call. The library doc guarantees +"Pixel-identical output." + +The verification renders **both** the original and the refactored card (both +write to the shared `/root/.hermes/ops-pulse.png`), captures each to a separate +file, and compares every pixel with numpy. Exit 0 on identity, exit 1 on any +mismatch or run failure. + +## The bug caught (data lost during DRY extraction) + +The first extraction into `_extracted_params.json` (and the hand-written +refactored card that followed it) silently dropped two pieces of the original: + +1. The **verdict subtext** line — original renders + `d.text((46, 134), "new 8th wizard "the Long View" added to + STANDING-AGREEMENT + WIZARDS-TABLE", font=font(17), fill=MUTED)`. + The refactored card had `verdict_subtext=''` (empty) and + `verdict_subtext_font_size=16` (should be 17). +2. The **first row** — original's first row is + `("Wizard that moved", "Sentinel — "the Long View" (new party, onboarded)", + BLUE)`. The refactored card listed only 5 rows (it started at "Claim + verdict"), omitting this BLUE row entirely. + +## Measured evidence (baseline = original render) + +Before the fix (refactored as shipped in the profile): + +``` +FAIL total pixel-diff=8295407 +diff bbox x[28..972] y[137..508] +diff pixels=72112 of 700000 +``` + +The diff band `y[137..508]` spans exactly the verdict subtext slot (y~134) plus +the entire row block — because dropping the subtext shifted nothing visually +subtext-wise, but dropping the first row shifted every subsequent row UP by +`y_step=54`, cascading a full-column mismatch. + +## The fix + +In `refactored_cards/ops-pulse-card-r41_refactored.py`: + +- `verdict_subtext` set to the original's subtext string; +- `verdict_subtext_font_size` corrected `16 -> 17` (matches original `font(17)`); +- `Row('Wizard that moved', 'Sentinel — "the Long View" (new party, onboarded)', + BLUE)` re-added as the first row. + +No geometry constants changed — `first_row_y=190`, `row_height=48`, +`ellipse_y0=19`, `ellipse_y1=31`, `y_step=54`, `value_x=330`, etc. all already +matched the originals (they were correct in the extraction defaults). + +## After the fix + +``` +PASS r41 pixel-identical (1000x700) — original vs refactored_card via ops_pulse_card_lib +exit=0 +``` + +Total pixel-diff = 0 across the full 1000x700 canvas (700,000 RGB pixels). + +## Reproducer / CHECK + +``` +python3 /root/.hermes/wizard-outputs/forge/verify_r41_pixel_diff.py +``` diff --git a/wizard-work/forge/_repro_bounds_original.py b/wizard-work/forge/_repro_bounds_original.py new file mode 100644 index 0000000..d13251d --- /dev/null +++ b/wizard-work/forge/_repro_bounds_original.py @@ -0,0 +1,24 @@ +"""Reproduce the chunk-token-overflow bug.""" +import sys +sys.path.insert(0, "/root/.hermes/wizard-outputs/forge") +import chunker + +cases = [ + ("Pack my box. ", 3, 0), + ("Pack my box. ", 3, 1), + ("Pack my box. ", 3, 2), + ("The quick brown fox jumps over the lazy dog. ", 11, 0), + ("The quick brown fox jumps over the lazy dog. ", 11, 5), +] +any_overflow = False +for txt, mt, ot in cases: + cs = chunker.chunk_text(txt, max_tokens=mt, overlap_tokens=ot) + for i, c in enumerate(cs): + body = c.partition(chunker._OVERLAP_SENTINEL)[2] if chunker._OVERLAP_SENTINEL in c else c + est = chunker.estimate_tokens(body) + if est > mt and body.strip(): + any_overflow = True + print(f"OVERFLOW mt={mt} ot={ot} chunk[{i}] body={body!r} est={est} > {mt}") +if not any_overflow: + print("No overflow found (unexpected).") +sys.exit(1 if any_overflow else 0) diff --git a/wizard-work/forge/refactored_cards/ops-pulse-card-r41_refactored.py b/wizard-work/forge/refactored_cards/ops-pulse-card-r41_refactored.py new file mode 100644 index 0000000..ffa7d14 --- /dev/null +++ b/wizard-work/forge/refactored_cards/ops-pulse-card-r41_refactored.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +"""Refactored ops-pulse-card-r41.py — same card, via ops_pulse_card_lib.""" +from __future__ import annotations +sys_path = __import__("sys"); sys_path.path.insert(0, '/root/.hermes/wizard-outputs/forge') +from ops_pulse_card_lib import CardParams, Row, GREEN, AMBER, RED, BLUE, BG, CARD, FG, MUTED, render_card, now_tick + +params = CardParams( + height=700, + tick='2026-10-15 20:59Z', + subtext='repo stackchain/troupe-standup · branch-head 7d2e679 (sentinel onboarding)', + verdict_text='SENTINEL ONBOARDED — MODEL CLAIM VERIFIED', + verdict_color=GREEN, + verdict_font_size=24, + verdict_subtext='new 8th wizard "the Long View" added to STANDING-AGREEMENT + WIZARDS-TABLE', + verdict_subtext_font_size=17, + verdict_subtext_y=134, + value_x=330, + value_font_size=16, + row_height=48, + ellipse_y0=19, + ellipse_y1=31, + label_y_offset=14, + value_y_offset=15, + y_step=54, + footer='no secrets · no invented progress · model spec cited to build.nvidia.com/nvidia/nemotron-3.5-super-vl-120b-a12b', + footer_font_size=13, + rows=[ + Row('Wizard that moved', 'Sentinel — "the Long View" (new party, onboarded)', BLUE), + Row('Claim verdict', 'Documented — model + spec confirmed (NVIDIA card / HF / blog)', GREEN), + Row('Model', 'Nemotron 3.5 Super VL · 120B MoE / 12B active · vision-language', GREEN), + Row('Access', 'NVIDIA NIM / opencode free tier — live-running on this host now', GREEN), + Row('My reply', 'none owed — no zephyrus ask this tick', MUTED), + Row('Needs your call', 'none new — no decision surfaced', MUTED), + ], +) +render_card(params) diff --git a/wizard-work/forge/verify_ops_pulse_refactor.py b/wizard-work/forge/verify_ops_pulse_refactor.py new file mode 100644 index 0000000..ccbe3f8 --- /dev/null +++ b/wizard-work/forge/verify_ops_pulse_refactor.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +"""Pixel-identity verification for the ops-pulse refactor. + +For every tick script (r33..r40, r37 was the precedent), compare the PNG +produced by the ORIGINAL source against the PNG produced by the REFACTORED +source (rendered via ops_pulse_lib). Exits 0 only if every pair is +pixel-identical (same size AND ImageChops.difference has no bbox). +""" +import sys + +from PIL import Image, ImageChops + +SCRIPTS = [33, 34, 35, 36, 38, 39, 40] +DIR = "/root/.hermes" + + +def check(nn: int) -> bool: + orig = Image.open(f"{DIR}/ops-pulse-r{nn}-ORIGINAL.png").convert("RGB") + new = Image.open(f"{DIR}/ops-pulse-r{nn}-REFACTORED.png").convert("RGB") + if orig.size != new.size: + print(f"r{nn}: SIZE MISMATCH {orig.size} vs {new.size}") + return False + bbox = ImageChops.difference(orig, new).getbbox() + if bbox is not None: + print(f"r{nn}: PIXEL MISMATCH at bbox {bbox}") + return False + print(f"r{nn}: pixel-identical ({orig.size[0]}x{orig.size[1]})") + return True + + +def main() -> int: + ok = True + for nn in SCRIPTS: + ok = check(nn) and ok + print("ALL_IDENTICAL" if ok else "MISMATCH_FOUND") + return 0 if ok else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/wizard-work/forge/verify_r41_pixel_diff.py b/wizard-work/forge/verify_r41_pixel_diff.py new file mode 100644 index 0000000..4c1e5be --- /dev/null +++ b/wizard-work/forge/verify_r41_pixel_diff.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +"""Verify the refactored ops-pulse card r41 is pixel-identical to the original. + +Runs the original card script (/root/.hermes/ops-pulse-card-r41.py) and the +refactored card script (refactored_cards/ops-pulse-card-r41_refactored.py) — +both write to the shared /root/.hermes/ops-pulse.png — captures each render to +a separate file, then compares every pixel with numpy. + +The refactor's contract: the DRY extraction into ops_pulse_card_lib must not +drop any data. A prior run of this very script failed to find this file +(RALPH LOOP); it also failed the behavioural check because the extraction had +silently dropped the verdict subtext line and the first ("Wizard that moved") +row. Both are now restored, so the two renders must be byte-identical. + +Exit 0 when pixel-identical, exit 1 on any mismatch or run failure. +""" +import os +import shutil +import subprocess +import sys + +import numpy as np +from PIL import Image + +FORGE = "/root/.hermes/wizard-outputs/forge" +ORIGINAL = "/root/.hermes/ops-pulse-card-r41.py" +REFACTORED = os.path.join(FORGE, "refactored_cards", "ops-pulse-card-r41_refactored.py") +SHARED_OUT = "/root/.hermes/ops-pulse.png" +BASELINE = os.path.join(FORGE, "refs", "r41_baseline.png") +TEST = os.path.join(FORGE, "_r41_test_render.png") + + +def run_script(path): + env = dict(os.environ) + env["PYTHONPATH"] = "/root" + os.pathsep + env.get("PYTHONPATH", "") + r = subprocess.run( + [sys.executable, path], + capture_output=True, text=True, env=env, timeout=120, + ) + if r.returncode != 0: + print(f"RUN FAIL {path} exit={r.returncode}") + print("stdout:", r.stdout) + print("stderr:", r.stderr) + sys.exit(1) + if not os.path.exists(SHARED_OUT): + print(f"RUN FAIL {path}: did not produce {SHARED_OUT}") + sys.exit(1) + return SHARED_OUT + + +def load(path): + return np.array(Image.open(path).convert("RGB")) + + +def main(): + os.makedirs(os.path.dirname(BASELINE), exist_ok=True) + + # 1) Original -> baseline + run_script(ORIGINAL) + shutil.copyfile(SHARED_OUT, BASELINE) + ref = load(BASELINE) + + # 2) Refactored -> test + run_script(REFACTORED) + shutil.copyfile(SHARED_OUT, TEST) + got = load(TEST) + + # 3) Pixel-diff + if ref.shape != got.shape: + print(f"FAIL shape mismatch: {ref.shape} vs {got.shape}") + sys.exit(1) + + diff = np.abs(ref.astype(int) - got.astype(int)) + total = int(diff.sum()) + if total == 0: + print(f"PASS r41 pixel-identical ({ref.shape[1]}x{ref.shape[0]}) — " + f"original vs refactored_card via ops_pulse_card_lib") + sys.exit(0) + + mask = diff.any(axis=2) + ys, xs = np.where(mask) + print(f"FAIL r41 pixel-diff total={total} across {len(ys)} px " + f"(of {mask.size}); bbox x[{xs.min()}..{xs.max()}] y[{ys.min()}..{ys.max()}]") + sys.exit(1) + + +if __name__ == "__main__": + main()