
    7,JjnA                    &   d Z ddlmZ ddlZddlZddlZddlmZ  ee      j                         j                  d   Zedz  ZdZdZg d	Zd
g dddg dddddgddg ddg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)$zOCheck whether the inherited-state predecessor is proven on the confirmed route.    )annotationsN)Path   outmap1_01amap2_02d)z#source-current-selector-merge-orderz$predecessor-branch-state-persistencezstrict-source-hotspotzout/save_scene_selectors.json)selectorselectedPointerHex	fieldMaps)pathfieldsz1out/save_selector_inherited_state_candidates.json)bestPreviouscurrentSelector
sharedMapsintroducedMapszout/playable_progress.jsonreachableFromStartconfirmedEdgesz.out/save_selector_predecessor_route_order.json)orderEvidenceremainingProofsrouteOrderProvenc                L    | j                  d       d| j                  d       S )Ngroup:slotget)rows    L/home/exedev/hwanse/tools/summarize_save_selector_predecessor_route_order.pyselector_keyr   (   s&    gggq 122    c                R    | D ]  }t        |      |k(  s|c S  t        d| d      )Nz	selector z
 not found)r   
ValueError)	selectorskeyr   s      r   find_selectorr%   ,   s9     #J yZ0
11r    c           	         | j                  d      xs g }t        |      }t        |       | j                  d      |t        |v t        |v t        ||z        dS )Nr   r
   )r	   rootHexr   containsSourcecontainsTargetconfirmedOverlap)r   setr   
SOURCE_MAP
TARGET_MAPsorted)r   confirmed_route_maps
field_maps	field_sets       r   selector_recordr2   3   s^    %+JJI %77/0$	1$	1"#7)#CD r    c                   |j                  d      xs i }|j                  d      xs d|j                  d      xs d}t        |       }t        | |      }|j                  d      xs g }|j                  d      xs g }t        |      }	t        |j                  d      xs g       t        |j                  d      xs g       }
t        |	|
z        }t        |	z        }| D cg c]Z  }|j                  d      rG|j                  d	      |j                  d
      f|j                  d	      |j                  d
      fk  r|\ }}|D cg c]2  }t        t        |j                  d      xs g       v rt        ||	      4 }}|D cg c]V  }t        t        |j                  d      xs g       v r0t        t        |j                  d      xs g       vrt        ||	      X }}|D cg c]E  }t        t        hj                  t        |j                  d      xs g             rt        ||	      G }}|j                  d        |j                  fd       |r|d   nd }t        v xr t        v}t        |
v xr' t        |
v xr t        |      xr t        |      xr | }dd d| dddd dt        |j                  d      xs g        d| d| ddj                  |j                  d      xs g       xs d d
dd|rdnd t         d!|xs i j                  dd"       d#dj                  |xs i j                  d$      xs g       xs d" ddd%|rd&nd' d(t         d)t        v  dt         d)t        v  d*|sd+nd, d-dd.|rd/nd0| d1t         dt         d2t        |       ddd3d4d5dj                  |       d6 d7dj                  |      xs d ddd8d4d9|rdj                  d: |D              nd;z   d< d=| dz   dg}t        |      xr t        fd>|D              }d?|xs i j                  dd@       dA| dB dCdDdEg}|rg nt        } dFt         dGt         dH|xs i j                  ddI       dJ| dKt         dLt         dM}i dNt        dOt        d|dP|j                  dQ      dRdS|j                  dQ      dT|j                  d      xs g dU|j                  d      xs g dV|d|dW|dX|dY|dZ|d[|d\|xs i j                  d      d]|xs i j                  d^      i d_|xs i j                  d$      xs g d`|dat        |      db|dcdddedk(  df|dg|dh|di|dj|r|ng dk|r|ng dlt        dmt        t              dndodp|dq|S c c}w c c}w c c}w c c}w )rNr   r	   z1:0r   z2:0r   r   r   r   r   c                *    t        | d          | d   fS )Nr*   r	   )len)items    r   <lambda>zbuild_summary.<locals>.<lambda>b   s     T:L5M1N0NPTU_P`/a r    )r$   c                    | d   k7  | d   fS )Nr	    )r6   predecessor_keys    r   r7   zbuild_summary.<locals>.<lambda>c   s    Z0@O0SUYZdUe/f r    r   zselector-indexzsupports-orderz& has a lower selector group/slot than .)kindstatusdetailzselector-progresszsupports-candidatez shares r   z maps with z and z introduces , r   zno mapszsource-side-selectorzconfirmed-route-overlapmissingz! is carried by previous selector nonez; confirmed overlap=r*   ztarget-side-predecessorztarget-state-onlyzalso-source-sidez
 contains =z; it is therefore znot  z1separate from the confirmed source-side selector.zselector-merge-shapezmerge-gap-openznot-merge-shapedz contains both z0; previous selectors containing both route maps=zconfirmed-routezdoes-not-prove-orderzconfirmed route reaches z; it overlaps z in zconfirmed-edgezconfirmed edges are c              3  f   K   | ])  }|j                  d        d|j                  d        + yw)sourcez->targetNr   ).0edges     r   	<genexpr>z build_summary.<locals>.<genexpr>   s0     hPT(!3 4Btxx7I6JKhs   /1emptyz; none executes z before c              3  n   K   | ],  }|j                  d       v xs |j                  d      v  . yw)rE   rF   Nr   )rG   rH   predecessor_mapss     r   rI   z build_summary.<locals>.<genexpr>   s>      E]a..X$((82DHX2XXEs   25zprove the source-side selector unknownz can progress into z after z state is establishedzKprove secondaryBranchState persists from predecessor fill to current readerz1find strict map1_01a source coordinate or hotspotz remains the strongest inherited secondaryBranchState producer candidate, but it is target-side only for this route: it contains z and does not contain z+. The confirmed source-side route overlaps zno previous selectorz, while z# looks like a merge of source-side z and target-side z lists. The fill effect must stay blocked until save progression, a strict hotspot, or a VM/runtime trace proves that this merge path executes the predecessor state before the current reader.rE   rF   currentRootHexr
   predecessorSelectorpredecessorRootHexpredecessorMapscurrentMapsconfirmedReachableFromStartpredecessorConfirmedOverlapcurrentConfirmedOverlapsourceSidePreviousSelectorstargetSidePreviousSelectorsroutePairPreviousSelectorssourceRoutePreviousSelectorsourceRoutePreviousRootHexr'   #sourceRoutePreviousConfirmedOverlappredecessorIsTargetSideOnlysamePreviousContainsRoutePairselectorMergeGapOpen%selectorIndexOrderSupportsPredecessorT#selectorProgressSupportsPredecessorr   
proofFoundpredecessorRouteOrderProofFound"failedPredecessorRouteOrderGateIdsmissingEvidencer   evidenceRefsevidenceRefCountpromotionStatusblockedr   
conclusion)r   r%   r+   r.   r,   r2   r-   issubsetsortboolr5   joinany'PREDECESSOR_ROUTE_ORDER_FAILED_GATE_IDS%PREDECESSOR_ROUTE_ORDER_EVIDENCE_REFS)r#   	inheritedplayablepredecessorcurrent_keypredecessor_rowcurrent_rowconfirmed_reachableconfirmed_edgesr/   current_mapscurrent_only_confirmedpredecessor_confirmed_overlapr   previous_rowssource_side_previoustarget_side_previousroute_pair_previoussource_route_previouspredecessor_is_target_side_onlyselector_merge_gap_openorder_evidenceroute_order_provenmissing_evidencefailed_gate_idsri   r:   rL   s                             @@r   build_summaryr   @   s,   --/52K!ooj1:UO-- 12;eK#I?O	;7K",,';<Bll#34:O23?..{;ArB{{39r:L#$8<$GH$*+?BR+R$S! 77;WWWswwv/;??73K[__]cMd2ee 	M  !SWW[17R88 	12  !SWW[17R88ZsSVSZSZ[fSgSmkmOn=n 	12  !
#,,S1E1K-LM 	12 
 "ab"fg7K03QU&04D&D&k[kIk#l" 	$,&	$%&	$ %&	$ $#  %&())OP[}\]^	
 (*"#8C0M0SQS,T+UU`al`m n"m<		+//JZ:[:a_a0b0ofo/ppqs		
 +3H/i,?)/R44ZHI J%%)YY0E0K/P/PQc/d/jhj%k%uou$vvwy		
 .-L)Rd"#:j\:IY;Y:ZZ_,a
.> >??Q!@6bIIz|		
 +*A&GY-zl%
| LAADEXAY@ZZ[]		
 &,*4995H+I*J.YhXiim99:;HyIL		
 %,& ' IIhXghh 	 %_$5Xk]!LM		
a=N| ;<  EetE B
 ./D/J.O.OPZ\e.f-g h!!,W_4EEZ\ 	V; /b4[O
 88B|CYZdYe f&'<'B&G&G
Tj&k%llt-::,FWXbWc dO	O #*#*# 	;# 	+//*>?	#
 	# 	o112FG# 	?..{;Ar# 	{{39r# 	&':# 	/# 	&'D# 	"#9# 	&';# 	&';# 	%&9#  	&(=(C'H'H'T!#" 	%'<'B&G&G	&R##$ 	.0E0K/P/PQc/d/jhj%#& 	&'F'#( 	(.A)B)#* 	 7+#, 	0-#. 	.%/G/#0 	.1#2 	(3#4 	*+=5#6 	-o7#8 	+B9#: 	+B;#< 	==#> 	C EF?#@ 	9A#B 	C#D 	jE# #e

s   +AV<7WAW.A
Wc                   ddd| d    d| d    dd| d	    d| d
    dddj                  | d          d| j                  d       ddj                  | j                  d      xs g       xs d d| j                  d       d| j                  d       ddj                  | d         xs d d| d    d| j                  d       d| j                  d       dd j                  | j                  d!      xs g       xs d" dd#t        | j                  d$      xs g        d%| j                  d&       d'| d(    d| d)   dd*dd+d,g}| d-   D ]&  }|j                  d.|d/    d0|d1    d0|d2    d3       ( |j	                  g d4       |j	                  d5 | d$   D               |j	                  g d6       | j                  d7      xs g D ]O  }|j                  d8|j                  d9       d:dj                  |j                  d;      xs g       xs d" d3       Q |j	                  g d<       |j	                  d= | d>   D               |j                  d       d?j                  |      S )@Nz'# Save Selector Predecessor Route OrderrC   z- predecessor: `rO   z` root `rP   `z- current: `r   rN   z- confirmed route: r?   rS   z"- source-side previous selector: `rY   z
` overlap r[   rA   z - predecessor target-side only: r\   z- selector merge gap open: r^   z!- predecessor confirmed overlap: rT   z- route order proven: r   z- proof found: ra   z'- predecessor route order proof found: rb   z)- failed predecessor route-order gates: `,rc   -z- missing evidence count: rd   z- evidence refs: rf   z- promotion status: rg   ri   z## Evidencez| kind | status | detail |z| --- | --- | --- |r   z| r<   z | r=   r>   z |)rC   z## Missing EvidencerC   c              3  &   K   | ]	  }d |   ywz- Nr9   rG   r6   s     r   rI   zmarkdown.<locals>.<genexpr>       D2dVD   )rC   z## Evidence RefsrC   z| path | fields |z| --- | --- |re   z| `r   z` | r   )rC   z## Remaining ProofsrC   c              3  &   K   | ]	  }d |   ywr   r9   r   s     r   rI   zmarkdown.<locals>.<genexpr>  r   r   r   
)rm   r   r5   appendextend)summarylinesr   s      r   markdownr      s   1

7#89:(7K_C`Baabc
w012(7CS;T:UUVW
dii0M(NOPQ
,W[[9V-W,XXbcgclclmtmxmx  z_  n`  nf  df  dg  dq  kq  cr  	s
*7;;7T+U*VW
%gkk2H&I%JK
+DIIg>[6\,],gag+hi
 );!< =>
'++l345
1'++>_2`1ab
3CHHW[[Im=n=trt4u4|y|3}}~
$S5F)G)M2%N$OP
GKK(:;<=
w'89:;


$/E2 ' Or#f+c#h-CM?"MNO	LL01	LLD1B)CDD	LLST{{>*0b _s3776?+4		#''(:K:Qr0R0YVY/ZZ\]^_	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 | j                  d      xs g D              }dj                  d	 | j                  d
      xs g D              }dj                  dddd| d    d| d    d| d    d| d    d	dt        j                  dj                  | d                ddt        j                  t	        | j                  d                   dt        j                  dj                  | j                  d      xs g       xs d       d| j                  d        d!| j                  d"       d	d#t        j                  dj                  | d$         xs d       dd%| d&    d'| j                  d(       d)t        j                  dj                  | j                  d*      xs g       xs d+       d,t        | j                  d      xs g        d-| j                  d.       d/t        j                  | d0          dd1t        j                  | d2          dd3|d4d5d6| d7d8d9|d4d:d6| d7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>r<   z	</td><td>r=   r>   
</td></tr>NhtmlescaperG   r   s     r   rI   zhtml_page.<locals>.<genexpr>  sg       	{{3v;'( ){{3x=)* +{{3x=)* +	s   AAr   rC   c              3  N   K   | ]  }d t        j                  |       d  ywz<li>z</li>Nr   r   s     r   rI   zhtml_page.<locals>.<genexpr>  s#     \tDKK-.e4\   #%r   c              3  N   K   | ]  }d t        j                  |       d  ywr   r   r   s     r   rI   zhtml_page.<locals>.<genexpr>  s#     g$T[[./u5gr   rd   c              3     K   | ]q  }d t        j                  t        |j                  d                   dt        j                  dj	                  |j                  d      xs g       xs d       d s yw)z<tr><td><code>r   z</code></td><td>r?   r   r   r   N)r   r   strr   rm   r   s     r   rI   zhtml_page.<locals>.<genexpr>  sq      
 		[[SWWV_!567 8{{499SWWX%6%<"=DEF G	s   A7A9re   zY<!doctype html><meta charset="utf-8"><title>Save Selector Predecessor Route Order</title>z<style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;max-width:1100px;margin:24px auto}table{border-collapse:collapse}td,th{border:1px solid #444;padding:6px 8px;vertical-align:top}code{color:#9bd4ff}</style>z.<h1>Save Selector Predecessor Route Order</h1>z<p>Predecessor <code>rO   z</code> root <code>rP   z</code>; current <code>r   rN   z</code>.</p>z<p>Confirmed route: r?   rS   z</p>z(<p>source-side previous selector: <code>rY   z</code>; overlap: r[   rA   z ; predecessor target-side only: r\   z; selector merge gap open: r^   z"<p>predecessor confirmed overlap: rT   z<p>route order proven: r   z; proof found: ra   z; failed route-order gates: rc   r   z; missing evidence count: z; evidence refs: rf   z; promotion status: rg   z<p>ri   zQ<table><thead><tr><th>kind</th><th>status</th><th>detail</th></tr></thead><tbody>z</tbody></table>z<h2>Missing Evidence</h2>z<ul>z</ul>z<h2>Evidence Refs</h2>zB<table><thead><tr><th>path</th><th>fields</th></tr></thead><tbody>z<h2>Remaining Proofs</h2>)rm   r   r   r   r   r5   )r   evidence_rowsproofsr@   evidence_refss        r   	html_pager     s   II  ?+ M WW\IZA[\\Fggg'++N_B`BfdfggGII 
 ;;~.4" M 99e 	n8
(= >??RSZ[oSpRq  rI  JQ  Rc  Jd  Ie  ex  y@  AQ  yR  xS  S_  	`
t{{499W=Z5[+\]^^bc
24;;s7;;OlCm?n3o2p  qC  DH  DO  DO  PT  PY  PY  Za  Ze  Ze  fK  ZL  ZR  PR  PS  P]  W]  D^  C_  _  @G  @K  @K  Li  @j  k  kF  GN  GR  GR  Si  Gj  Fk  ko  	p
,T[[7KhCi9j9tnt-u,vvz{%g.@&A%B C#KK56 7))-TYYw{{Ko?p?vtv5w5~{~)  )A A''*7;;7H+I+OR'P&Q R%kk*<=> ?!!%W5F-G!H IO dkk',/016[#
wiu L#
vhe7  r    c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okz*save_selector_predecessor_route_order.jsonF   )ensure_asciiindentr   utf-8encoding*save_selector_predecessor_route_order.html)mkdir
write_textjsondumpsr   )r   out_dirs     r   write_outputsr   =  sf    MM$M.;;GG

7q9D@ H  ;;GG	RYHZelGmr    c            	        t        j                         } | 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                  |j                  j                  d	
            t        j                  |j                  j                  d	
            t        j                  |j                  j                  d	
                  }t        ||j                         t        d|j                  dz          y )Nz--selectorszsave_scene_selectors.json)typedefaultz--inheritedz-save_selector_inherited_state_candidates.jsonz
--playablezplayable_progress.jsonz	--out-dirr   r   z!wrote predecessor route order -> r   )argparseArgumentParseradd_argumentr   OUT
parse_argsr   r   loadsr#   	read_textrq   rr   r   r   print)parserargsr   s      r   mainr   F  s   $$&F
D#@[:[\
D#@o:op
4?W9WX
$<D

4>>++W+=>

4>>++W+=>

4==**G*<=G
 '4<<(	-dll=i.i-j
klr    __main__)r   dictreturnr   )r#   
list[dict]r$   r   r   r   )r   r   r/   zset[str]r   r   )r#   r   rq   r   rr   r   r   r   )r   r   r   r   )r   r   r   r   r   None)r   r   )__doc__
__future__r   r   r   r   pathlibr   __file__resolver   ROOTr   r,   r-   ro   rp   r   r%   r2   r   r   r   r   r   __name__r9   r    r   <module>r      s    U "     H~''*
Ul

+ ' 0A
 DU
 -')9:
 AJ) %(32
bJ$N.bnm  zF r    