
    UHj-4                       d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	  ee
      j                         j                  d   Zedz  ZdZd	Zd
ZdZdZddZddZddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZddZddZedk(  r e        yy)zGConsolidate the selector-merge evidence for the map1_01a route blocker.    )annotationsN)Path)Any   outmap1_01amap2_02dz0:0z1:0z2:0c                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)pathfallbacks     >/home/exedev/hwanse/tools/summarize_save_selector_merge_gap.py	load_jsonr      s*    ;;=::dnngn677    c                    |j                  dd      \  }}t        |      }t        |      }| D ]B  }|j                  d      |k(  s|j                  d      |k(  s-|j                  d      xs g c S  g S )N:r   groupslot	fieldMapssplitintget)	selectorskey
group_text	slot_textr   r   rows          r   selector_mapsr%      ss    IIc1-J	
OEy>D .777u$D)@77;'-2-. Ir   c                    |j                  dd      \  }}t        |      }t        |      }| j                  d      xs g D ]/  }|j                  d      |k(  s|j                  d      |k(  s-|c S  i S )Nr   r   progressRowsr   r   r   )progressr!   r"   r#   r   r   r$   s          r   progress_rowr)   %   sr    IIc1-J	
OEy>D||N+1r 777u$D)@J Ir   c                T	   t        | t              }t        | t              }t        | t              }t	        |t              }	|	j                  d      xs g }
t        d |
D        i       }t        d |
D        i       }t        d |
D              }|j                  d      xs i }|j                  d      xs i }|j                  d      xs i }|j                  d      xs i }|j                  d	      xs g }|j                  d
      du }|j                  d      du }t        |v xr t        |vxr t        |v xr t        |vxr t        t        hj                  t        |            xrk | xrf |j                  d      xs ddk(  xrL |j                  d      xs ddk(  xr2 |j                  d      xs ddk(  xr |j                  d      du xr | }dt        |v r
t        |vrdndt         ddj                  |      xs d ddt        |v r
t        |vrdndt         ddj                  |      xs d ddt        t        hj                  t        |            rdndt         dt         dt        |v  dt         dt        |v  	ddd d!|j                  d"       d#|j                  d"       d$| d%dd&d't         d(|j                  d       d)t         d*|j                  d       d%dd+d,t         d(|j                  d       d)t         d*|j                  d       d-|j                  d.       d%
dd/|sd0nd1d2dj                  |      xs d d3| d4| d%dd5d6d7|j                  d8       d9|j                  d:       d;|j                  d<       d%dg}d=}i d>t        d?t        d@t        dAt        dBt        dC|dD|dE|dF|j                  dG      xs g dH|j                  dG      xs g dI|dJ|j                  dd      dK|j                  dd      dL|j                  dd      dM|j                  dd      dN|j                  d      dO|j                  dP      ||||j                  d8      |j                  d:      |j                  dQ      |d6|g dR|dSS )TNpreviousCandidatesc              3  R   K   | ]  }|j                  d       t        k(  s| ! yw	fromLabelN)r   SOURCE_SELECTOR.0r$   s     r   	<genexpr>z build_summary.<locals>.<genexpr><   !     kS377;CW[jCjSk   ''c              3  R   K   | ]  }|j                  d       t        k(  s| ! ywr-   )r   TARGET_SELECTORr0   s     r   r2   z build_summary.<locals>.<genexpr>=   r3   r4   c              3     K   | ]<  }t         |j                  d       xs g v xr t        |j                  d       xs g v  > yw)fromFieldMapsN)SOURCEr   TARGETr0   s     r   r2   z build_summary.<locals>.<genexpr>>   sG      & 	377?+1r2av#''/BZB`^`7aa&s   AAconfirmedToFrontierfrontierToConfirmedpredecessorToCurrentcurrentToPredecessorsampleSelectorscurrentFrontierSampleCoveredTroutePairSampleCovereddwordHitCountr   hitCountreverseHitsOnlyBeforeFillzsource-side-selectorzsource-onlymixedz maps=z, -)kindstatusdetailztarget-side-selectorztarget-onlyzcurrent-selectorzcontains-route-pairzmissing-route-mapz maps include =zprogress-candidateszsplit-source-targetzbest previous=r.   z; source previous=z$; same previous contains route pair=.zsource-current-bridgezno-direct-bridgez->2:0 hits=z; 2:0->z hits=ztarget-current-bridgezreuse-only-before-fillz; reverse hits before fill=reverseHitsBeforeFillCountzpublic-savedata-sampleszno-current-frontier-samplecoveredzsample selectors=z; current covered=z; route pair covered=persistenceblockedz
wouldPass=%predecessorFillWouldPassCurrentReaderz; routeOrder=routeOrderProvenz; selectorMergeGap=selectorMergeGapOpenaM  The current selector 2:0 contains both the confirmed source-side map1_01a and the target-side map2_02d list, but the evidence remains a split selector merge rather than a proven transition. Selector 0:0 carries the confirmed source route without map2_02d; selector 1:0 carries map2_02d without map1_01a. There is no direct 0:0<->2:0 bridge, no forward 1:0->2:0 bridge, and the 2:0->1:0 reverse hits only point before the secondary fill sites. Public savedata samples do not cover selector 2:0. Promotion therefore still needs a selector 2:0 save/runtime trace or a strict map1_01a hotspot.sourcetargetsourceSelectortargetSelectorcurrentSelectorsourceSelectorMapstargetSelectorMapscurrentSelectorMapssourceCandidateSharedMaps
sharedMapstargetCandidateSharedMapssamePreviousContainsRoutePairsourceToCurrentBridgeHitCountcurrentToSourceBridgeHitCounttargetToCurrentBridgeHitCountcurrentToTargetBridgeHitCounttargetReverseHitsOnlyBeforeFill targetReverseHitsToFillSiteCountreverseHitsToFillSiteCountpersistenceProven)zHcapture or construct a savedat/runtime trace whose scene selector is 2:0zfprove the 0:0 source-side route can enter 2:0 after the 1:0 target-side secondary state is establishedzPfind a strict map1_01a source coordinate, hotspot, or equivalent runtime trigger)r@   rA   r?   predecessorPersistenceWouldPasspredecessorRouteOrderProvenpredecessorPersistenceProvenrR   promotionStatusevidenceremainingProofs
conclusion)r%   r/   r6   CURRENT_SELECTORr)   r   nextanyr9   r:   issubsetsetjoin)r    scene_selector_progressmap1_selector_bridge_refspredecessor_bridge_refssavedata_sample_coveragepredecessor_persistence_gapsource_mapstarget_mapscurrent_mapscurrent_progressprevious_candidatessource_candidatetarget_candidatesame_previous_contains_pairsource_bridgefrontier_bridgepredecessor_to_currentcurrent_to_predecessorselectors_seencurrent_sample_coveredsample_route_pair_coveredmerge_gap_openrk   rm   s                           r   build_summaryr   /   s<     	?;K	?;K ,<=L#$;=MN*../CDJk,?kmopk,?kmop"% &&& # .112GHNBM/334IJPbO4889OPVTV4889OPVTV-112CDJN599:XY]aa 8 < <=U VZ^ ^+ 
	'+%
	'k!
	' +%
	' V%%c,&78	
	'
 ,+
	' /41:
	'   16Q1<
	' $''
38qQ>
	' $''(CDL
	' '&  +'-'<{AZm`g()		+0F0M#/NO	
 +'-'<{AZm`g()		+0F0M#/NO	
 '06/?/H/H\IZ/[+at)*.&LBXAYY[\b[ccdeko{e{d|}	
 *+ !1!5!5k!B C D##3#7#7#D"E F55P4QQRT		
 ,("#;}/@/@/Q.R S'(/B/B?/S.TTUW		
 ,."#;/E/I/I*/U.V W'(/E/I/I*/U.V W,,C,G,GHd,e+ffgi		
 .:P2V_#DIIn$=$D#E F##9"::OPiOjjkm		
 "8<<=def g9==>PQR S$$?$C$CDZ$[#\\]_		
e;Hz	; !&!&! 	/! 	/	!
 	+! 	k! 	k! 	|! 	$%5%9%9,%G%M2! 	$%5%9%9,%G%M2! 	()D! 	():):?A)N! 	()<)<_a)P! 	()?)C)CJPQ)R! 	()?)C)CJPQ)R!  	*+B+F+FGb+c!!" 	+,C,G,GHd,e#!$ )?";)+F+J+JKr+s'B'F'FGY'Z(C(G(GH[(\ .$

 !A! !r   c                   ddd| d    d| d    d| d    d	d
| d    d	d| d    d	d| d    d| d    d| d    d| d    d| d    d| d    d| d    d| d    d| d    d| d   dd dd!d"g}| d#   D ]&  }|j                  d$|d%    d&|d'    d&|d(    d)       ( |j                  g d*       |j                  d+ | d,   D               |j                  d       d-j                  |      S ).Nz# Save Selector Merge Gap z	- route: rS   z -> rT   z- source-side selector: `rU   `z- target-side selector: `rV   z- current selector: `rW   z%- same previous contains route pair: r^   z- source/current bridge hits: r_   z / r`   z- target/current bridge hits: ra   rb   z(- target reverse hits only before fill: rc   z#- current frontier sample covered: r@   z- selector merge gap open: rR   z- promotion status: rj   rm   z## Evidencez| kind | status | detail |z| --- | --- | --- |rk   z| rG   z | rH   rI   z |)r   z## Remaining Proofsr   c              3  &   K   | ]	  }d |   yw)z- N r1   items     r   r2   zmarkdown.<locals>.<genexpr>   s     D2dVDs   rl   
)appendextendrs   )summarylinesr$   s      r   markdownr      s   #

GH%&d78+<*=>
#G,<$=#>a@
#G,<$=#>a@
(9 :;1=
/8W0X/YZ
(1P)Q(RRUV]^}V~U  	A
(1P)Q(RRUV]^}V~U  	A
27;\3]2^_
-g6T.U-VW
%g.D&E%FG
w'89:;


$)E, z" Or#f+c#h-CM?"MNO	LL01	LLD1B)CDD	LL99Ur   c                   dj                  d | d   D              }dj                  d | d   D              }dj                  ddd	d
t        j                  | d          dt        j                  | d          d| d    d| d    d| d    dd| d    d| d    ddt        j                  | d          dd|ddd | d!g      S )"Nr   c           
   3     K   | ]R  }d t        j                  |d          dt        j                  |d          dt        j                  |d          d T yw)z<tr><td>rG   z	</td><td>rH   rI   z
</td></tr>Nhtmlescaper0   s     r   r2   zhtml_page.<locals>.<genexpr>   sg       	{{3v;'( ){{3x=)* +{{3x=)* +	s   AArk   r   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li>z</li>Nr   r   s     r   r2   zhtml_page.<locals>.<genexpr>   s#     \tDKK-.e4\s   #%rl   zK<!doctype html><meta charset="utf-8"><title>Save Selector Merge Gap</title>z<style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;max-width:1200px;margin:24px auto}table{border-collapse:collapse;width:100%}td,th{border:1px solid #444;padding:6px 8px;vertical-align:top}code{color:#9bd4ff}</style>z <h1>Save Selector Merge Gap</h1>z
<p>Route: rS   z -&gt; rT   z; source-side selector <code>rU   z$</code>; target-side selector <code>rV   z </code>; current selector <code>rW   z</code>.</p>z<p>selector merge gap open: rR   z; promotion status: <code>rj   z</code></p>z<p>rm   z</p>zQ<table><thead><tr><th>kind</th><th>status</th><th>detail</th></tr></thead><tbody>z</tbody></table>z<h2>Remaining Proofs</h2>z<ul>z</ul>)rs   r   r   )r   evidence_rowsproofss      r   	html_pager      s]   II  :& M WW\IZA[\\F99W 	y*
T[[!234GDKKPXHY<Z;[[x  zA  BR  zS  yT  Tx  y@  AQ  yR  xS  Ss  t{  |M  tN  sO  O[  	\
&w/E'F&GGabij{b|a}  ~I  	J
dkk',/016[#
vhe  r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       y )
NT)parentsexist_oksave_selector_merge_gap.jsonF   )ensure_asciiindentr   r   r   )mkdir
write_textr   dumps)r   out_dirs     r   write_outputsr      sC    MM$M.--99

7q9D@ : r   c                 j   t        j                         } | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t        dz         | j                  dt        t        d	z         | j                  d
t        t        dz         | j                  dt        t        dz         | j                  dt        t               | j                         }t        t        |j                  g       t        |j                  i       t        |j                  i       t        |j                  i       t        |j                  i       t        |j                  i             }t        ||j                         t!        d|j                  dz          y )Nz--selectorszsave_scene_selectors.json)typedefaultz--scene-selector-progresszscene_selector_progress.jsonz--source-bridgez"map1_01a_selector_bridge_refs.jsonz--target-bridgez*save_selector_predecessor_bridge_refs.jsonz--savedata-sampleszsavedata_sample_coverage.jsonz--persistence-gapz.save_selector_predecessor_persistence_gap.jsonz	--out-dirz!wrote save selector merge gap -> r   )argparseArgumentParseradd_argumentr   OUT
parse_argsr   r   r    rt   r   target_bridgesavedata_samplespersistence_gapr   r   print)parserargsr   s      r   mainr      sm   $$&F
D#@[:[\
3$NlHlm
)cDh>hi
)cDp>pq
,4GfAfg
+$Fv@vw
$<D$.."%$..3$$$b)$$$b)$'',$&&+G '4<<(	-dll=[.[-\
]^r   __main__)r   r   r   r   returnr   )r    
list[dict]r!   strr   z	list[str])r(   dictr!   r   r   r   )r    r   rt   r   ru   r   rv   r   rw   r   rx   r   r   r   )r   r   r   r   )r   r   r   r   r   None)r   r   )__doc__
__future__r   r   r   r   pathlibr   typingr   __file__resolver   ROOTr   r9   r:   r/   r6   rn   r   r%   r)   r   r   r   r   r   __name__r   r   r   <module>r      s    M "      H~''*
Ul		 8LL!L  $L "	L
 #L "&L 
L^>2_, zF r   