import html,json
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/l92';rows=json.loads((O/'results.json').read_text())['records'];table=[]
for study in ('r107','r108'):
 for view in ('clipped','complete'):
  a=[x for x in rows if x['study']==study and x['view']==view];tr=sum(x['trigger'] for x in a)
  for budget in ('10','30','60','all'):
   vals=[sum(x['scores'][k][budget]['0.5']['matched'] for x in a) for k in ('baseline','boundary','conditional')];table.append(f'<tr><td>{study}</td><td>{view}</td><td>{tr}/8</td><td>{budget}</td>'+''.join(f'<td>{v}/8</td>' for v in vals)+'</tr>')
cards=[]
for r in rows:
 vals=[r['scores'][k]['10']['0.5']['matched'] for k in ('baseline','boundary','conditional')];cards.append(f'<section><h2>{html.escape(r["study"])} field {html.escape(r["name"])}: {html.escape(r["view"])}</h2><p>Gate {"triggered" if r["trigger"] else "did not trigger"}; first-ten matches variance / boundary / conditional: {" / ".join(map(str,vals))} of one selected reference region. Top-ten boundary contacts: {html.escape(str(r["first10_edge_contact"]))} pixels.</p><a href="{html.escape(r["panel"])}"><img loading="lazy" src="{html.escape(r["panel"])}" alt="Selected source reference, variance, boundary and conditional mask lists"></a><p><a href="/{html.escape(r["source"])}">Native public source image</a> · <a href="/results/{html.escape(r["study"])}/{html.escape(r["archive"])}">Saved boundary predictions</a></p></section>')
(O/'index.html').write_text('''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>L92 candidate-edge gate</title><style>body{font:16px/1.5 system-ui;color:#18342f;max-width:1200px;margin:2em auto;padding:0 1em}a{color:#006b59}img{max-width:100%}table{border-collapse:collapse}td,th{border:1px solid #bbc;padding:.4em}.warn{background:#fff2d6;padding:1em}section{border-top:1px solid #ccd}</style><a href="/results/board.html">Research board</a> · <a href="/results/r107/">First boundary study</a> · <a href="/results/r108/">Four-edge replay</a><h1>L92: Can candidate edge contact trigger extra prompts?</h1><p class="warn">Retrospective exploration on 32 previously viewed views from 16 source fields. Clips were constructed using reference geometry; backgrounds have incomplete labels. A mask touching an edge may be a real object, background, a partial object or an artifact. The gate is not a biological identity decision or an independent test of natural partials.</p><p>Inspect the first ten saved padding-deferred variance masks. Trigger an extra boundary-prompt stream if any one mask occupies at least eight pixels along a known content-boundary line. When triggered, alternate the existing variance and boundary candidate lists, starting with variance; otherwise keep the original variance stream. No reference labels enter the gate or ranking. Every displayed mask costs one slot; no new cross-stream suppression is applied.</p><table><tr><th>Parent study</th><th>View</th><th>Gate triggered</th><th>Budget</th><th>Variance-only</th><th>Boundary-only</th><th>Conditional mix</th></tr>'''+''.join(table)+'''</table><p>Each entry is one-to-one recovery of eight selected source regions at IoU ≥0.5. The gate triggers on <strong>31 of 32</strong> views, including 15 of 16 complete views. On R107 clipped cases, variance / boundary / conditional top-30 results are 5/8 / 7/8 / 5/8. On R108 clipped cases they are 8/8 / 8/8 / 6/8. Mixing can displace useful candidates at the same display budget. These results do not justify deploying the gate.</p><p>Hypothetical standalone execution on these 32 views would use 16,128 point queries, compared with 8,192 for variance-only; the separate-run image-encoding upper bound is 1,008 versus 512. Tile encodings could potentially be shared, but no such implementation, runtime or review-time measurement was made here. Existing original predictions, aliases and images are retained; if the gate does not trigger, the separate boundary archive still exists for later inspection.</p><p>Source/archive hashes, edge-contact counts, gate outcomes, candidate rankings, cross-stream overlap links and scores were independently reconstructed. Verification shares the matcher and did not rerun neural inference. This is a negative result for one simple fixed heuristic, not a conclusion about all possible adaptive methods.</p><p><a href="protocol.json">Protocol</a> · <a href="results.json">Per-view gate and scores</a> · <a href="verify.log">Verification</a> · <a href="/research/L92.md">Research note</a></p>'''+''.join(cards)+'</html>')
