
    UHjp=                    N   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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	 	 	 	 	 	 	 	 	 	 	 	 d dZ	 	 	 	 	 	 	 	 	 	 d!dZd"dZd"dZefd#dZd$dZedk(  r e        yy)%zNSeparate confirmed map1_01a entry context from selector-only frontier context.    )annotationsN)Path   outmap1_01amap1_02bmap2_02dc                    | j                  d      }t        |t              r|S | j                  d      }t        |t              rd|dS y)NrecordVaHexrecordVa0x08xnone)get
isinstancestrint)rowvalues     =/home/exedev/hwanse/tools/summarize_map1_01a_entry_context.py
record_hexr      sI    GGM"E%GGJE%E#;    c                    | j                  d      xs g D ]-  }t        fd|j                  d      xs g D              s+|c S  y )Nclustersc              3  F   K   | ]  }|j                  d       k(    ywr   Nr   ).0recordrecord_va_hexs     r   	<genexpr>z%cluster_for_record.<locals>.<genexpr>   s     mfvzz-(M9m   !manifestRecordsr   any)field_rootsr    clusters    ` r   cluster_for_recordr(      sH    ??:.4" mTeHfHljlmmN r   c                    | j                  d      xs g D ]-  }t        fd|j                  d      xs g D              s+|c S  y )Nr   c              3  F   K   | ]  }|j                  d       k(    ywr   r   )r   r   event_record_va_hexs     r   r!   z$cluster_for_event.<locals>.<genexpr>%   s      pFvzz-(,??pr"   eventRecordsr$   )r&   r+   r'   s    ` r   cluster_for_eventr-   #   sH    ??:.4" pgkkZhNiNomoppN r   c                    g }| j                  t              xs i j                  d      xs g D ];  }t        fd|j                  d      xs g D              s+|j                  |       = |S )Nrecordsc              3  F   K   | ]  }|j                  d       k(    ywr   r   )r   scener    s     r   r!   z$records_for_scene.<locals>.<genexpr>-   s     ^Uuyy'=8^r"   scenes)r   MAPr%   append)save_selector_scene_linksr    rowsr   s    `  r   records_for_scener7   *   sg    D)--c28b==iHNB ^cgghFWF][]^^KK Kr   c                    t               }g }| D ]C  }|j                  d      xs g D ])  }||v r|j                  |       |j                  |       + E |S )Ntargetssetr   addr4   )r6   seenr9   r   targets        r   selector_targetsr?   2   sc    5DG #ggi(.B 	#F~HHVNN6"		## Nr   c                    g }t               }| D ]N  }|j                  d       d|j                  d       }||v r-|j                  |       |j                  |       P |S )Nselector:leafPointerHexr:   )r6   labelsr=   r   labels        r   selector_labelsrF   >   sj    F5D 77:&'q1A)B(CDD=e Mr   c                D   g }| D ]  }|j                  d      t        k7  st        |j                  d      xs g vr8|j                  |j                  d      t        t	        |      |j                  d      |j                  d      xs g |j                  d      xs g |j                  d      xs g D cg c]T  }t        |j                  d      xs g v r7|j                  d      |j                  d      |j                  d      xs g d	V c}d
        |S c c}w )Nmapr9   
sceneIdHexactivePointsconditionChoicesconditionVaHexpayloadVaHexlinkedStrings)rL   rM   rN   )sourcer>   r   rI   rJ   r9   conditionPayloads)r   CONFIRMED_PREVIOUSr3   r4   r   )event_transitionsr6   eventchoices       r   confirmed_incomingrU   J   s   D" 99U11S9AUA[Y[5\ii&%e,))L1!IIn5;yy+1r $ii(:;Ar" 6::i06B7 '-jj1A&B$*JJ~$>%+ZZ%@%FB"
 	( K"s   6ADc                v    t        |      }| |k(  ry| |k(  st        |v ry|r|j                  d      dk(  ry|ryy)Nzconfirmed-entry-contextzselector-only-frontier-contextclassificationstrict event-linked clusterzstrict-event-linked-contextzselector-linked-contextzmanifest-only-context)r?   FRONTIER_TARGETr   )r    r'   selector_rowsconfirmed_entry_record_hexfrontier_record_hexr9   s         r   role_for_recordr]   c   sL    }-G22(++'/I/7;;/04QQ,("r   c                r   g }| D ]  }|j                  d      t        k7  rt        |      }t        ||      }t	        ||      }	|j                  ||j                  d      |j                  d      xs g |j                  d      xs g D 
cg c]  }
|
j                  d       c}
|j                  d      xs g D 
cg c]  }
|
j                  d       c}
|xs i j                  d      |xs i j                  d      |xs i j                  d	d
      |xs i j                  dd      |xs i j                  d      xs g |xs i j                  d      xs g |xs i j                  dd      t        |	      t        |	      t        |||	||      d        |j                  d        |S c c}
w c c}
w )NrH   rI   tilesets	resourcesnamefollowingResourcesclusterStartHexclusterEndHexrW   z not-in-interesting-root-clusterseventRecordCountr   eventSourceseventFieldLinkssaveSelectorRefCount)r   rI   r_   resourceNamesfollowingResourceNamesrc   rd   clusterClassificationre   rf   rg   rh   selectorTargetsselectorLabelsrolec                    | d   S )Nr    )r   s    r   <lambda>z'build_record_contexts.<locals>.<lambda>   s    #m"4 r   )key)
r   r3   r   r(   r7   r4   r?   rF   r]   sort)scene_manifestr&   r5   r[   r\   contextsmanifest_recordr    r'   rZ   resources              r   build_record_contextsrx   p   s    H) u%,"?3$[-@)*C]S()--l;'++J7=2CRCVCVWbCcCigijxhll62jL[L_L_`tLuL{y{&|x||F';&| '2223DE%m00A&-m%8%89IKm%n!(B 3 34F J$]//?E2 '2223DEK%,]$7$78NPQ$R/>-m<#M7MKegz{
 	. MM4M5O k&|s   F/=F4c                   t        |      }|D ch c]  }|d   	 }}d}d }|D ]_  }	t        ||	      }
|
s|
j                  d      xs g D ]/  }|j                  d      t        k(  s|j                  d      }|
} n |dk7  s_ n |j                  t              xs i j                  d      xs g D cg c]  }t        |j                  d      xs g v r|! }}d}|rH|d   j                  d      xs g D ]-  }|j                  d      t        k(  s|j                  d      } n t        | ||||      }|dk7  rt        ||      nd }|dk7  xr& |dk7  xr ||k(  xr |xs i j                  d	      d
k(  }d}t        t        t        |||xs i j                  d      ||xs i j                  d      |D cg c]j  }|j                  d      |j                  d      |j                  d      xs g |j                  d      xs g D cg c]  }|j                  d       c}dl c}}|d|g d|dS c c}w c c}w c c}w c c}}w )Nr   r   r#   rH   r/   r9   r   r2   rW   rX   aX  Confirmed play reaches map1_01a through the strict map1_02b event cluster at 0x005032d8/0x00503350, while the map2_02d successor hint lives in the separate 0x00542b44 selector-only cluster. Those are different scene clusters, so the save-selector adjacency is not proven to be the current map1_01a runtime context or a normal transition target.rc   rA   rC   )rA   rC   r9   sceneRecordsblocked)z]prove selector 2:0 / 0x00542b44 is reached from the confirmed map1_02b -> map1_01a entry pathzRor find a strict map1_01a source coordinate/hotspot in the confirmed entry contextz8or keep map1_01a -> map2_02d as selector-only trial data)rH   frontierTargetconfirmedPreviousconfirmedIncomingTransitionsconfirmedEntryRecordHexconfirmedEntryClusterHexfrontierRecordHexfrontierClusterHexfrontierSelectors frontierProvenFromConfirmedEntrypromotionStatusrecordContextsremainingProofs
conclusion)rU   r-   r   r3   rY   rx   r(   rQ   )rt   rR   r&   r5   incomingr   incoming_event_hexesr[   confirmed_entry_cluster	event_hexr'   r   frontier_rowsr\   r1   record_contextsfrontier_clusterfrontier_provenr   s                      r   build_summaryr      s    ""34H:BC3C.CC!'") 
	#K;kk"34: 	Fzz% C'-3ZZ-F**1'		
 &/
 .11#6<"AA)LRPRswwy17R8 	M 
 !"1%))(39r 	Eyy3&&+ii&>#	
 ,!"O PcflOl)+7JKrv"f, 	\6)	\&*==	\ #(()9:>[[	 	B  )/(0#=%<%B$G$GHY$Z0/52::;LM %
   GGJ/"%''*:";779-3GJwwxGXG^\^ _e=!9 _	
 -<$)

 !5 _ D\ !`
s$   H24$H76AIH<"I<I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g}| d   D ]  }|d    ddj                  |d         xs d ddj                  |d         xs d }|j                  d|d    d|d    d |d!    d"|j                  d#      xs d d| d d$j                  |d%         xs d d d$j                  |d&         xs d d d$j                  |d'         xs d d d$j                  |d(         xs d d)        |j                  g d*       | d+   D ]  }d$j                  d, |j                  d-      xs g D              }d$j                  d. |j                  d/      xs g D              }|j                  d0|d1    d2|d    d3|d4    d5|xs d d6|xs d 
        |j                  g d7       |j                  d8 | d9   D               |j                  d       d:j                  |      S );Nz# map1_01a Entry Context z- confirmed previous: `r}   `z- frontier target: `r|   z- confirmed entry record: `r   z- frontier record: `r   z(- frontier proven from confirmed entry: r   z- promotion status: `r   r   z## Record Contextsz[| record | role | cluster | events | selector targets | selectors | resources | following |z1| --- | --- | --- | --- | --- | --- | --- | --- |r   re    src=,rf   - links=rg   z| `r   z` | rn   z | rk   z `rc   , rl   rm   ri   rj   z |)r   z## Confirmed Incomingr   r~   c              3  f   K   | ])  }|j                  d        d|j                  d        + yw)xr   yNr   )r   points     r   r!   zmarkdown.<locals>.<genexpr>  s-     kEeiin-Quyy~.>?ks   /1rJ   c              3  F   K   | ]  }|j                  d       xs d  yw)rM   r   Nr   )r   payloads     r   r!   zmarkdown.<locals>.<genexpr>  s!     rGW[[8?C?rs   !rP   z- `rO   @z` -> `r>   z	` active=z
 payloads=)r   z## Remaining Proofsr   c              3  &   K   | ]	  }d |   yw)z- Nrp   r   items     r   r!   zmarkdown.<locals>.<genexpr>  s     D2dVDs   r   
)joinr4   r   extend)summarylinesr   eventspointspayloadss         r   markdownr      s   "

!'*=">!?qA
w'789;
%g.G&H%IK
w':;<A>
27;]3^2_`
(9 :;1=


e;E" '( 
*+,E#((3~;N2O2VSV1WW^_b_g_ghkl}h~_  `G  DG  _H  I#m$%T#f+c#>U:V9WWYZ]ZaZabsZtZ{x{Y|  }Ahc$))C(9$:;BsC3tyyQTUeQfGgGnknFooryy_-.5#6c$))CH`Da:b:ifi9jjln	

 
LL2356 IkSWWUcMdMjhjkk99rswwWjOkOqoqrrs3x=/3}+=*>fS]OS\]c]jgj\kkuv~  wF  CF  vG  H  	II 
LL01	LLD1B)CDD	LL99Ur   c                "   g }| d   D ]  }|d    ddj                  |d         xs d ddj                  |d         xs d }|j                  d	t        j                  |d
          dt        j                  |d          dt        j                  |d          dt        j                  |j	                  d      xs d       dt        j                  |       dt        j                  dj                  |d         xs d       dt        j                  dj                  |d         xs d       dt        j                  dj                  |d         xs d       dt        j                  dj                  |d         xs d       d        dj                  d | d   D              }dj                  d | d   D              }dj                  g dddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1t        j                  | d2          d3t        j                  | d4          d5| d6    d7t        j                  | d8          d9	d:t        j                  | d;          d<d=d>|d?d@dA| dBdCdA| dBdDdEd      S )FNr   re   r   r   rf   r   r   rg   z<tr><td><code>r   z</code></td><td>rn   z	</td><td>rk   z <code>rc   r   rl   rm   ri   rj   z
</td></tr>r   c           
   3     K   | ]R  }d t        j                  |d          dt        j                  |d          dt        j                  |d          d T yw)z
<li><code>rO   r   r   z</code> -> <code>r>   z</code></li>Nhtmlescape)r   r   s     r   r!   zhtml_page.<locals>.<genexpr>  se      
 		S]+,Adkk#m:L.M-N OS]+, -	s   AAr~   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li>z</li>Nr   r   s     r   r!   zhtml_page.<locals>.<genexpr>"  s#     \tDKK-.e4\s   #%r   r   z<!doctype html>z<html lang="en">z<head>z  <meta charset="utf-8">zF  <meta name="viewport" content="width=device-width, initial-scale=1">z'  <title>map1_01a Entry Context</title>z	  <style>zg    :root { color-scheme: dark; font-family: system-ui, sans-serif; background: #101010; color: #eee; }z&    body { margin: 0; padding: 24px; }z,    h1 { margin: 0 0 8px; font-size: 24px; }z/    h2 { margin: 24px 0 8px; font-size: 18px; }z<    p { max-width: 1100px; color: #bbb; line-height: 1.45; }z[    table { width: 100%; border-collapse: collapse; margin: 12px 0 20px; font-size: 13px; }zi    th, td { border-bottom: 1px solid #303030; padding: 7px 8px; text-align: left; vertical-align: top; }zF    th { position: sticky; top: 0; background: #181818; color: #ddd; }z    code { color: #d7f0ff; }z
  </style>z</head>z<body>z!  <h1>map1_01a Entry Context</h1>z  <p>confirmed entry <code>r   z</code>; frontier record <code>r   z/</code>; frontier proven from confirmed entry: r   z; promotion status <code>r   z</code></p>z  <p>r   z</p>z  <h2>Record Contexts</h2>z  <table><thead><tr><th>record</th><th>role</th><th>cluster</th><th>events</th><th>selector targets</th><th>selectors</th><th>resources</th><th>following</th></tr></thead><tbody>z  </tbody></table>z  <h2>Confirmed Incoming</h2>z  <ul>z</ul>z  <h2>Remaining Proofs</h2>z</body>z</html>)r   r4   r   r   r   )r   r6   r   r   r   proofss         r   	html_pager     s   D'( 
*+,E#((3~;N2O2VSV1WW^_b_g_ghkl}h~_  `G  DG  _H  IS%789 :;;s6{+, -;;s#:;<=WT[[QTQXQXYjQkQrorEsDt u;;v&' (;;tyy->)?@GCHI J;;tyy-=)>?F3GH I;;tyy_)=>E#FG H;;tyy-E)FGN3OP Q		

 ww 
 9: H WW\IZA[\\F99 %%% 	% 	#	%
 	Q% 	2% 	% 	r% 	1% 	7% 	:% 	G% 	f% 	t% 	Q%  	'!%" 	#%$ 	%%& 	'%( 	,)%* &dkk':S2T&U%V W!!%W5H-I!J K L1189[1\0] ^""&++g6G.H"I!J+	W+%2 GL123483%4 	%5%6 	}7%8 
9%: 	;%< 	(=%> 
% ?%@ 	&A%B C%D 	E%F 	G%H 	I% % %r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       y )
NT)parentsexist_okmap1_01a_entry_context.jsonF   )ensure_asciiindentr   utf-8encoding)mkdir
write_textjsondumps)r   out_dirs     r   write_outputsr   K  sC    MM$M.,,88

7q9D@ 9 r   c            
     n   t        j                  t              } | 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                  |j                  j                  d            t        j                  |j                  j                  d            t        j                  |j                  j                  d            t        j                  |j                  j                  d                  }t        ||j                          t#        d|j                   dz          y )N)descriptionz--scene-manifestzscene_manifest.json)typedefaultz--event-transitionszevent_transitions.jsonz--field-rootszfield_map_record_roots.jsonz--save-selector-scene-linkszsave_selector_scene_links.jsonz	--out-dirr   r   z wrote map1_01a entry context -> r   )argparseArgumentParser__doc__add_argumentr   OUT
parse_argsr   r   loadsrt   	read_textrR   r&   r5   r   r   print)parserargsr   s      r   mainr   S  sY   $$9F
*sEZ?Z[
-D#H`B`a
dCB_<_`
5D#PpJpq
$<D

4&&00'0BC

4))33W3EF

4##--w-?@

411;;W;MN	G '4<<(	,T\\<Y-Y,Z
[\r   __main__)r   dictreturnr   )r&   r   r    r   r   dict | None)r&   r   r+   r   r   r   )r5   r   r    r   r   
list[dict])r6   r   r   z	list[str])rR   r   r   r   )r    r   r'   r   rZ   r   r[   r   r\   r   r   r   )rt   r   r&   r   r5   r   r[   r   r\   r   r   r   )
rt   r   rR   r   r&   r   r5   r   r   r   )r   r   r   r   )r   r   r   r   r   None)r   r   )r   
__future__r   r   r   r   pathlibr   __file__resolver   ROOTr   r3   rQ   rY   r   r(   r-   r7   r?   rF   rU   r]   rx   r   r   r   r   r   __name__rp   r   r   <module>r      s   T "     H~''*
Ul 		2
#     $  !$	 
    FQQ!Q Q  $	Q
 
Qh!H=@ 25 ]$ zF r   