
    UHjS                    b   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	g d
ddg ddgZg dZg dZg dZd"dZd#dZd$dZd%dZd&dZeed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)/z=Summarize the strict event-link gap for map1_01a -> map2_02d.    )annotationsN)Path   outmap1_01amap2_02dzout/field_map_record_roots.json)
clustersstrictEventLinkedClusterCountselectorOnlyClusterCount
proofFoundfieldMapRecordRootsProofFoundfailedFieldMapRecordRootGateIdsmissingEvidenceevidenceRefsevidenceRefCountpromotionStatus)pathfieldszout/event_transitions.json)maptargetseventDispatchRefsconditionLinkedStrings)zdirect-strict-event-transitionzsource-outgoing-strict-clusterztarget-strict-clusterz'selector-only-frontier-not-event-linked)z3direct strict event transition map1_01a -> map2_02dz@strict event cluster sourced by map1_01a and linking to map2_02dz)strict target-linked cluster for map2_02dzInon-selector-only current frontier event link or equivalent trigger proof)z?find a direct strict event transition from map1_01a to map2_02dzGfind a source-outgoing strict cluster from map1_01a that links map2_02dz0find a strict target-linked cluster for map2_02dzZreplace selector-only frontier adjacency with a strict event or equivalent runtime triggerc                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)r   fallbacks     F/home/exedev/hwanse/tools/summarize_map1_01a_strict_target_link_gap.py	load_jsonr#   =   s*    ;;=::dnngn677    c                B    dj                  d | xs g D              xs dS )N,c              3  2   K   | ]  }t        |        y w)N)str).0values     r"   	<genexpr>zcsv.<locals>.<genexpr>D   s     95CJ9s   -)join)valuess    r"   csvr/   C   s     889FLb99@S@r$   c                R    | sy| j                  d       d| j                  d       S )Nr,   clusterStartHexz..clusterEndHexgetclusters    r"   cluster_ranger7   G   s.    kk+,-RO0L/MNNr$   c                <   t        | j                  d      xs g       }| j                  d      xs g D ]S  }|j                  d      xs g D ]9  }t        |t              s|j	                  d      s&|j                  |d d        ; U t        t        |            S )Nr   r   r   z.cns)listr4   
isinstancer(   endswithappendsortedset)eventr   refr*   s       r"   event_targetsrB   M   s    599Y'-2.Gyy,-3 +WW56<" 	+E%%%..*@uSbz*	++ #g,r$   c                |    | j                  d      | j                  d      | j                  d      t        |       dS )Nr   recordVaHexrawPointCount)r   rD   rE   r   )r4   rB   )r@   s    r"   compact_eventrF   V   s8    yyyy/?3 '	 r$   )sourcetargetc          
        | j                  d      xs g }| j                  d      xs g }| j                  d      xs g }| j                  d      xs g }| j                  d      xs g D cg c]I  }|j                  d      |j                  d      |j                  d      |j                  d	      xs g d
K }}i dt        |       d| j                  d      d| j                  d      d| j                  d      d|d|d|d| j                  dd      d|d| j                  dd      d| j                  dd      dt        |      dt        |      dt        fd|D              dt        fd|D              dt        fd|D              d|v |v |v xr |v|v |v t	        fd|D              t	        fd|D              dS c c}w )NmanifestMapseventSourceseventFieldLinks
routePairseventRecordsrD   r   
pointCount
fieldLinks)rD   r   rO   rP   clusterRangeHexr1   r2   classificationeventRecordCountr   saveSelectorRefCountcurrentFrontierPairCountmanifestMapCountroutePairCountsourceOutgoingRoutePairCountc              3  L   K   | ]  }|j                  d       k(  sd  yw)rG   r   Nr3   )r)   rowrG   s     r"   r+   z"compact_cluster.<locals>.<genexpr>{   &      ,
(9V(CA,
   $$targetIncomingRoutePairCountc              3  L   K   | ]  }|j                  d       k(  sd  yw)rH   r   Nr3   )r)   rZ   rH   s     r"   r+   z"compact_cluster.<locals>.<genexpr>~   r[   r\   sourceTargetRoutePairCountc              3  r   K   | ].  }|j                  d       k(  r|j                  d      k(  rd 0 yw)rG   rH   r   Nr3   r)   rZ   rG   rH   s     r"   r+   z"compact_cluster.<locals>.<genexpr>   s:      *
wwx F*swwx/@F/J *
   47containsSourcec              3  r   K   | ].  }|j                  d       k(  xr |j                  d      k(   0 ywrG   rH   Nr3   ra   s     r"   r+   z"compact_cluster.<locals>.<genexpr>   s=      (
 GGH'GCGGH,=,GG(
rb   c              3     K   | ]A  }|j                  d       k(  xr' |j                  d      k(  xr |j                  d       C yw)rG   rH   isCurrentFrontierNr3   ra   s     r"   r+   z"compact_cluster.<locals>.<genexpr>   sV      &
  GGH' -!V+-+,-&
s   AA
)containsTargetincomingOnlyForSourceoutgoingFromSourcelinksTargethasSourceTargetRoutePairhasCurrentFrontierPair)r4   r7   lensumany)	r6   rG   rH   manifest_mapsevent_sourcesevent_linksroute_pairsrecordevent_recordss	    ``      r"   compact_clusterrw   _   sx   KK/52MKK/52M++/06BK++l+1rK kk.17R  "::m4::e$ **\2 **\28b		
M (=1(7;;'89( 	_5( 	'++&67	(
 	( 	( 	;( 	GKK(:A>( 	( 	,BA F( 	#GKK0JA$N( 	C.( 	#k*( 	' ,
$,
 )
(" 	' ,
$,
 )
#(( 	%c *
"*
 '
)(2 	&M13(4 !M1!';!6!V6;V$5,$' (
"(
 %
 #& &
 #	&
 #
E( (s   .AG!c                0    || j                  d      xs g v S )NrJ   r3   )r6   map_names     r"   contains_maprz      s    N39r::r$   c                X    | j                  d      dk(  xs | j                  dd      dkD  S )NrR   zstrict event-linked clusterrS   r   r3   r5   s    r"   	is_strictr|      s0    ;;'(,IIsW[[YkmnMorsMssr$   c                Z    | j                  dd      dk(  xr | j                  dd      dkD  S )NrS   r   rT   r3   r5   s    r"   is_selector_onlyr~      s1    ;;)1-2aw{{CY[\7]`a7aar$   c                    | D ]e  }|j                  d      xs g D ]K  }|j                  d      t        k(  s|j                  d      t        k(  s5|j                  d      sG|c c S  g y )NrM   rG   rH   rg   r4   SOURCETARGET)r	   r6   pairs      r"   find_current_frontier_clusterr      sg     KK-3 	D"f,HHX&&0HH01	 r$   c                   | j                  d      xs g }|D cg c]-  }|j                  d      t        k(  rt        t        |      v r|/ }}|D cg c]  }t	        |      rt        |t              r|! }}|D cg c]:  }t        |j                  d      xs g v rt        |j                  d      xs g vr|< }}|D cg c]  }t        |j                  d      xs g v r|! }}|D cg c]  }t	        |      rt        |t              r|! }	}|D cg c]  }t        |      rt        |t              r|! }
}|
D cg c]  }t        |t              s| }}|
D cg c])  }t        d |j                  d      xs g D              r|+ }}t        |      }|rt        |      nd }|xs i j                  dd      }|xs i j                  d	d      }|xs i j                  d
d      }t        |      xs t        d |D              }t        |xr7 |j                  dd      dk(  xr  dt        |j                  d      xs d      v       }i dt        dt        dt        |      d|D cg c]  }t        |       c}dt        |      d|D cg c]  }t        |       c}dt        |      dt        |      dt        |	      d|	D cg c]  }t        |       c}dt        |
      d|
D cg c]  }t        |       c}dt        |      dt        |      d|rdndd |xs i j                  d!      d"||||xs i j                  d#      |||d$d$t        t        t         t"        t        t"              d%d&d'}|S c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w )(Nr	   r   rL   rK   c              3     K   | ]6  }|j                  d       t        k(  xr |j                  d      t        k(   8 ywre   r   )r)   rZ   s     r"   r+   z build_summary.<locals>.<genexpr>   s<      
 GGH'GCGGH,=,GG
s   <>rM   rW   r   rX   r]   c              3     K   | ]<  }t         |j                  d       xs g v xr t        |j                  d      xs g v  > yw)rK   rL   N)r   r4   r   r)   r6   s     r"   r+   z build_summary.<locals>.<genexpr>   sP      A  	7;;~.4"5 	=w{{#45;<	=As   AArS   zselector-onlyrR    rG   rH    directStrictEventTransitionCountdirectStrictEventTransitionssourceStrictClusterCountsourceStrictClusters$sourceIncomingOnlyStrictClusterCount sourceOutgoingStrictClusterCounttargetStrictClusterCounttargetStrictClusterstargetSelectorOnlyClusterCounttargetSelectorOnlyClusters$targetSelectorOnlySourceOverlapCount3targetSelectorOnlySourceTargetRoutePairClusterCount-targetSelectorOnlyCurrentFrontierClusterCountr   currentFrontierManifestMapCountrV   currentFrontierRoutePairCountr_   Fblockeda  Strict event evidence around map1_01a is incoming-only: the nearby strict cluster 0x005032d8..0x00503350 is sourced by map1_02b and links into map1_01a. No strict event transition starts at map1_01a and targets map2_02d, while map2_02d appears only in selector-only clusters, including the current frontier 0x00542b44..0x00542e74. The only selector-only cluster that overlaps both source and target is that current frontier, where the source-target edge is one member of a broad route-pair list rather than an event row. This keeps map1_01a -> map2_02d blocked until a strict source hotspot, runtime trace, or equivalent trigger proof is found.)+currentFrontierSourceOutgoingRoutePairCount+currentFrontierTargetIncomingRoutePairCount)currentFrontierSourceTargetRoutePairCountcurrentFrontierCluster$currentFrontierClusterIsSelectorOnlystrictTargetLinkFoundr   strictTargetLinkProofFoundfailedStrictTargetLinkGateIdsr   remainingProofsr   r   r   
conclusion)r4   r   r   rB   r|   rz   r~   rp   r   rw   boolr(   rn   rF   "FAILED_STRICT_TARGET_LINK_GATE_IDS#STRICT_TARGET_LINK_MISSING_EVIDENCE#STRICT_TARGET_LINK_REMAINING_PROOFSEVIDENCE_REFS)field_map_rootsevent_transitionsr	   r@   direct_strict_eventsr6   source_strict_clusterssource_incoming_only_clusterssource_outgoing_clusterstarget_strict_clusterstarget_selector_only_clusters#target_selector_only_source_overlap0target_selector_only_source_target_pair_clusterscurrent_frontier_clustercurrent_frontier!current_frontier_route_pair_count&current_frontier_source_outgoing_count&current_frontier_target_incoming_countstrict_target_link_found!current_frontier_is_selector_onlysummarys                        r"   build_summaryr      s   "":.4"H '99Uv%&M%4H*H 	   (W,w"? 	 
  6%gkk"34:;w{{[iOjOpnp@q 	%! %
  6 gkk.17R8 	   
  (W,w"? 	 
  (%G$gv)F 	%! %
  =+WV\@]+' +
 58 
{{<06B
 
 	84 8  =XFD\'?@bf)9)?R(D(DEUWX(Y%.>.D"-I-I&.* /?.D"-I-I&.*  $$89  S A .A >
 )-  	Y$(();Q?1D	Ys#;#?#?@P#Q#WUWXX)%
.&.&. 	+C0D,E. 	'K_(`%u)=(`	.
 	#C(>$?. 	I_ `g!9 `. 	/4Q0R. 	+C0H,I. 	#C(>$?. 	I_ `g!9 `. 	)#.K*L. 	%Ol&mGw'?&m. 	/4W0X. 	>s<@
." 	8>V\]#.$ 	*,<,B+G+GHZ+[%.& 	()J'.( 8^7]6F6L"5Q5Q(6
 #30Q!9&+)K>>%.$jK.G^ NM
% %+8> )a ` !a&msM   2N
$N<?N$N+$N$N#?N(N(.N-.N2N7N<8O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&j                  | j                  d'      xs g       xs d( d)t        | j                  d*      xs g        d+| d,    d-| d.    dd| d/   dd0dg}|j                  d1 | j                  d*      xs g D               |j                  g d2       |j                  d3 | j                  d4      xs g D               |j                  g d5       | j                  d6      xs g D ]E  }|j	                  d7|j                  d8       d9t        |j                  d:      xs g        d;       G |j                  g d<       | d=   D ]  }d&j                  d> |j                  d?      xs g D              }|j                  d@      rdAn|j                  dB      rdCnd(}|j	                  d7|dD    d9|dE    dFd&j                  |dG         xs d( dFd&j                  |dH         xs d( dF|xs d( dF| d;        |j                  g dI       | dJ   D ]J  }|j	                  d7|dD    d9|dE    dF|dK    dF|dL    dF|dM    dF|dN    dF|dO    dF|dP    dF|dQ    d;       L |j	                  d       dRj                  |      S )SNz!# map1_01a Strict Target Link Gapr   z- route under test: `rG   z -> rH   `z#- direct strict event transitions: r   z- source strict clusters: r   z(- source incoming-only strict clusters: r   z#- source outgoing strict clusters: r   z- target strict clusters: r   z!- target selector-only clusters: r   z3- target selector-only clusters containing source: r   z5- target selector-only source->target pair clusters: r   zN- current frontier selector-only route pairs/source outgoing/target incoming: r   z / r   r   z"- current frontier selector-only: r   z- strict target link found: r   z- proof found: r   z"- strict target-link proof found: r   z#- failed strict target-link gates: , r   r,   z- missing evidence count: r   z- evidence refs: r   z- promotion status: `r   r   z## Missing Evidencec              3  &   K   | ]	  }d |   ywz- N r)   items     r"   r+   zmarkdown.<locals>.<genexpr>:       N2dVN   )r   z## Remaining Proofsr   c              3  &   K   | ]	  }d |   ywr   r   r   s     r"   r+   zmarkdown.<locals>.<genexpr>@  r   r   r   )r   z## Evidence Refsr   z| path | fields |z| --- | --- |r   z| `r   z` | r   z |)r   z## Source Strict Clustersr   zH| cluster | class | event sources | event links | event records | role |z%| --- | --- | --- | --- | --- | --- |r   c              3  F   K   | ]  }|j                  d       xs d  ywrD   r,   Nr3   r)   ru   s     r"   r+   zmarkdown.<locals>.<genexpr>R  s!     mFJJ}5<<m   !rN   ri   incoming-onlyrj   outgoingrQ   rR   z | rK   rL   )r   z ## Target Selector-Only Clustersr   z| cluster | class | selector refs | maps | route pairs | source outgoing | target incoming | source->target | current frontier |z=| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |r   rT   rV   rW   rX   r]   r_   rm   
)r-   r4   rn   extendr=   r/   )r   linesrA   r6   recordsroles         r"   markdownr     s5   +

 12$wx7H6IK
-g6X.Y-Z[
$W-G%H$IJ
27;a3b2cd
-g6X.Y-Z[
$W-G%H$IJ
+G4T,U+VW
=gFl>m=no
?H}@~?  	A
X23
4C@A
B#@A
B	D -W5[-\,]^
&w/F'G&HI
',/01
,W5Q-R,ST
-diiDc8d8jhj.k.ror-st
$S5F)G)M2%N$OP
G$6789
(9 :;1=


9E< 
LLN5F)G)M2NN	LL  
 
LLN5F)G)M2NN	LL   {{>*0b Rs3776?+4CGGH4E4K0L/MRPQR	LL   12 
))m7;;WeKfKljlmm")++.E"FZaZeZefzZ{J  BE'+,-T':J2K1LCyy018S9yy!234;<C3?OsSWRXXZ\	

 
LL   78 
'+,-T':J2K1LC-./s7;M3N2Os'()W5S-T,UUX567s7C_;`:aad/01	5	

 
LL99Ur$   c           %     L   dj                  d | j                  d      xs g D              }dj                  d | j                  d      xs g 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j                  d | d   D              }dj                  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+t        | j                  d      xs g        d,| j                  d-       d.| d/    d0d1t        j                  | d2          d3d4| d5d6| d5d7| d5d8d9|d:d;d<|d:d=d>|d:d?d@dg      S )ANr   c              3  N   K   | ]  }d t        j                  |       d  ywz<li>z</li>Nhtmlescaper   s     r"   r+   zhtml_page.<locals>.<genexpr>m  s(      ,0$t{{4 !'   #%r   c              3  N   K   | ]  }d t        j                  |       d  ywr   r   r   s     r"   r+   zhtml_page.<locals>.<genexpr>p  s#     g$T[[./u5gr   r   c              3  N   K   | ]  }d t        j                  |       d  ywr   r   r   s     r"   r+   zhtml_page.<locals>.<genexpr>q  s#     iD$t{{4017ir   r   r   c              3     K   | ]g  }d t        j                  t        |j                  d                   dt        j                  t	        |j                  d      xs g              d i yw)<tr><td><code>r   </code></td><td>r   
</td></tr>N)r   r   r(   r4   r/   )r)   rA   s     r"   r+   zhtml_page.<locals>.<genexpr>r  sg      "
 		[[SWWV_!567 8{{3swwx06B789 :	"s   A-A/r   c              3  $  K   | ]  }d t        j                  |d          dt        j                  t        |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	 |j	                  d
      xs g D              xs d       d|j	                  d      rdn|j	                  d      rdnd d 
 yw)r   rQ   r   rR   	</td><td>r   rK   r,   rL   c              3  F   K   | ]  }|j                  d       xs d  ywr   r3   r   s     r"   r+   z&html_page.<locals>.<genexpr>.<genexpr>  s!     $v&VZZ%>%E#%E$vr   rN   ri   r   rj   r   r   N)r   r   r(   r-   r4   r   s     r"   r+   zhtml_page.<locals>.<genexpr>y  s     
 	[[):!;<= >{{3w'789:; <{{499W^%<=DEF G{{499W->%?@GCHI J{{499$vT[T_T_`nToTusu$vv}z}~ @")++.E"FZaZeZefzZ{J  BE  F F	
s   DDr   c              3     K   | ]l  }d t        j                  |d          dt        j                  t        |d                d|d    d|d    d|d    d|d    d|d	    d|d
    d|d    d n yw)r   rQ   r   rR   r   rT   rV   rW   rX   r]   r_   rm   r   N)r   r   r(   r   s     r"   r+   zhtml_page.<locals>.<genexpr>  s       	[[):!;<= >{{3w'789:; <-./ 0)*+ ,'() *567 8567 8345 6/01 2
	s   A2A4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">z0  <title>map1_01a Strict Target Link Gap</title>a    <style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;margin:24px}table{border-collapse:collapse;width:100%;max-width:1200px}td,th{border:1px solid #333;padding:6px 8px;text-align:left;vertical-align:top}th{background:#1f1f1f}code{color:#9bd4ff}</style>z</head>z<body>z*  <h1>map1_01a Strict Target Link Gap</h1>z  <p>route <code>rG   z -&gt; rH   z#</code>; direct strict transitions r   z; target strict clusters r   z2; target selector-only clusters containing source r   z; current frontier route pairs r   z; strict target link found: r   z; proof found: r   z"; strict target-link proof found: r   z; missing evidence count z; evidence refs r   z; promotion status <code>r   z</code>.</p>z  <p>r   z</p>z.  <h2>failed strict target-link gates</h2><ul>z</ul>z  <h2>Missing Evidence</h2><ul>z  <h2>Remaining Proofs</h2><ul>z  <h2>Evidence Refs</h2>zD  <table><thead><tr><th>path</th><th>fields</th></tr></thead><tbody>z  </tbody></table>z!  <h2>Source Strict Clusters</h2>z  <table><thead><tr><th>cluster</th><th>class</th><th>event sources</th><th>event links</th><th>event records</th><th>role</th></tr></thead><tbody>z(  <h2>Target Selector-Only Clusters</h2>z  <table><thead><tr><th>cluster</th><th>class</th><th>selector refs</th><th>maps</th><th>route pairs</th><th>source outgoing</th><th>target incoming</th><th>source-&gt;target</th><th>current frontier</th></tr></thead><tbody>z</body>z</html>)r-   r4   rn   r   r   )r   failed_gatesmissing	remainingevidence_ref_rowssource_rowstarget_rowss          r"   	html_pager   l  s~   77 4;KK@_4`4fdf L ggg'++N_B`BfdfggGiGKKPaDbDhfhiiI		 "
 ;;~.4""  )) 
 56
 
K ))  ;< K 99"P: 	\4
GH-.ggh6G5H I%%,-O%P$Q R"")*D"E!F G;9:
; <((/0O(P'Q R%%,-D%E$F G-. /++23O+P*Q R""%gkk2C&D&J"K!L M %789 :"")*;"<!=\	K GL12348
8eL
)'%8
))E:"N+ 	^2 	k
S* * *r$   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       y )
NT)parentsexist_ok$map1_01a_strict_target_link_gap.jsonF   )ensure_asciiindentr   r   r   )mkdir
write_textr   dumps)r   out_dirs     r"   write_outputsr     sD    MM$M.55AA

7q9D@ B r$   c                 f   t        j                  t              } | j                  dt        t
               | j                         }t        t        |j                  dz  i       t        |j                  dz  g             }t        ||j                         t        d|j                  dz          y )N)descriptionz	--out-dir)typedefaultzfield_map_record_roots.jsonzevent_transitions.jsonz)wrote map1_01a strict target link gap -> r   )argparseArgumentParser__doc__add_argumentr   OUT
parse_argsr   r#   r   r   print)parserargsr   s      r"   mainr    s    $$9F
$<D$,,!>>C$,,!992>G '4<<(	5dllEk6k5l
mnr$   __main__)r   r   )r.   zlist[object] | Nonereturnr(   )r6   dict | Noner  r(   )r@   dictr  z	list[str])r@   r  r  r  )r6   r  rG   r(   rH   r(   r  r  )r6   r  ry   r(   r  r   )r6   r  r  r   )r	   
list[dict]r  r  )r   r  r   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   r   r   r   r   r   r   r#   r/   r7   rB   rF   rw   rz   r|   r~   r   r   r   r   r   r  __name__r   r$   r"   <module>r     s    C "     H~''*
Ul		 6	
  -
!4& "' #' #8AO  5;& 6r;tb	hVNbPf 25 	o zF r$   