
    JJj                    ~   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	 ddl
mZ  e	e      j                         j                  d   Zedz  Zd	Zd
Zedz  Zedz  Zedz  Zedz  Zedz  ZdZdZdZdZdZdg dddg dddg dddg dddg d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$dAd)Z%dBd*Z&dCd+Z'	 	 	 	 	 	 dDd,Z(dEd-Z)dFd.Z*	 	 	 	 	 	 dGd/Z+dHd0Z,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dId1Z-dJd2Z.d:d3Z/edddddf	 	 	 	 	 	 	 	 	 	 	 	 	 dKd4Z0dLd5Z1dLd6Z2edfdMd7Z3dNd8Z4e5d9k(  r e4        yy)Oz2Summarize predecessor-save runtime route attempts.    )annotationsN)Counter)Path)Any   out%runtime_selected_pointer_predecessor_z
_poll.jsonz!save_selector_mapset_aliases.jsonz(save_selector_scene_adjacency_index.jsonz0save_selector_global_selected_pointer_paths.jsonzsave_scene_selectors.jsonz#save_scene_selector_references.json1:02:0
0x00540714map1_01amap2_02d3out/runtime_selected_pointer_predecessor_*poll.json)uniqueSelectorContextsrouteSelectorHitCountcurrentRootHitCountuniqueWatchValues)pathfieldsz%out/save_selector_mapset_aliases.json)duplicateGroupstargetAliasGroupaliases	fieldMapsz,out/save_selector_scene_adjacency_index.json)pairRows	selectorsstrictEventBackedconfirmedReviewBackedselectorAdjacencyOnlyz4out/save_selector_global_selected_pointer_paths.json)selectorRootScansselectedRootExecutionRefFoundopcode07SelectsCurrentRootCountopcode09StoresCurrentRootCountzout/save_scene_selectors.json)groupslotselectedPointerHexr   z'out/save_scene_selector_references.json)labelresourcefilenamesceneMatchedpathHexc                L    t        j                  | j                  d            S Nutf-8encoding)jsonloads	read_textr   s    P/home/exedev/hwanse/tools/summarize_runtime_predecessor_route_attempt_context.py	load_jsonr5   W   s    ::dnngn677    c                p    | j                         r%t        j                  | j                  d            S i S r,   )existsr0   r1   r2   r3   s    r4   load_optional_jsonr9   [   s)    ;?;;=4::dnngn67PbPr6   c                    | j                   }|j                  t              r|t        t              d  }|j	                  t
              r|d t        t
                }|j                  dd      S )N_-)name
startswithPREFIXlenendswithSUFFIXreplace)r   r=   s     r4   short_labelrD   _   sV    99DvCKL!}}VNs6{l#<<S!!r6   c           
         t               }| D ]Y  }|j                  d      xs g D ]?  }|j                  d      }|s||xx   t        |j                  d      xs d      z  cc<   A [ |S )Nr   selectorcountr   )r   getint)rowscountsrowitemrF   s        r4   selector_countsrN   h   su    "9F @GG45; 	@Dxx
+Hx C(9(>Q$?? 	@@
 Mr6   c                   t               }| D ]  }|j                  d      xs i }|j                         D ]d  \  }}|j                  |      s|xs g D ]D  }|j                  d      }|s|| d| xx   t	        |j                  d      xs d      z  cc<   F f  t        t        |j                                     S )Nr   valueHex=rG   r   )r   rH   itemsr>   rI   dictsorted)	rJ   prefixrK   rL   uniquekeyvaluesvalue	value_hexs	            r4   watch_value_countsr[   r   s    "9F Q,-3!<<> 	QKC>>&)2 Q!IIj1	cU!I;/0C		'8J8Oa4PP0Q	QQ v||~&''r6   c                :    syt        fd| xs g D              S )NFc              3  :   K   | ]  }t        |      k(    y w)N)str).0rY   rF   s     r4   	<genexpr>z#selector_matches.<locals>.<genexpr>   s     @%s5zX%@s   )any)rX   rF   s    `r4   selector_matchesrb      s    @6<R@@@r6   c                f   g }| D ]  }t        |j                  d      xs i j                  |      xs d      }|s7|j                  |j                  d      |j                  d      ||t        |j                  d      xs d      z  |j                  d      |j                  d      d	        |S )
NselectorCountsr   r   r&   sampleCountr   r   r   )r   r&   re   selectorShareOfFiler   r   )rI   rH   append)filesrF   rJ   rM   rG   s        r4   selector_context_rowsri      s    !#D TXX./52::8DIJHHV$XXg& #(3txx/F/K!+L#L%)XX.E%F#'88,A#B
 		 Kr6   c                2   |si S t        | j                  d      xs g       }| j                  d      xs i }|r|j                  |       |D ]G  }|j                  d      xs g D ]-  }t        |t              s|j                  d      |k(  s)|c c S  I i S )Nr   r   r   rF   )listrH   rg   
isinstancerS   )mapset_aliasesrF   groupstarget_groupr#   aliass         r4   find_alias_grouprq      s    	.$$%67=2>F!%%&89?RLl# YYy)/R 	E%&599Z+@H+L	 Ir6   c                    | j                  d      xs g D ]+  }t        |t              s|j                  d      |k(  s)|c S  i S )Nr   rF   )rH   rl   rS   )alias_grouprF   rp   s      r4   	alias_rowrt      sE    +1r eT"uyy'<'HL Ir6   c                T   g }| j                  d      xs g D ]  }t        |j                  d      |      s |j                  |j                  d      |j                  d      |j                  d      |j                  d      xs g |j                  d      xs g |j                  d      xs g |j                  d      xs g t        |j                  d	            t        |j                  d
            t        |j                  d            |j                  d      d        |S )Nr   r   sourcetargetoccurrenceCountleafPointerssourceRecordstargetRecordsr   r   r   classification)rv   rw   rx   r   ry   rz   r{   r   r   r   r|   )rH   rb   rg   bool)scene_adjacencyrF   rJ   rL   s       r4   scene_adjacency_rowsr      s    !#D"":.4" CGGK0(;KK''(+''(+#&77+<#= WW[17R # 7 =2!$!9!?R!$!9!?R%)#''2E*F%G)-cgg6M.N)O)-cgg6M.N)O"%''*:";  Kr6   c                .   |si S | j                  d      xs g D ]w  }t        |j                  d      |      s i d|j                  d      d|j                  d      xs g d|j                  d      d|j                  d      d|j                  d      dt        |j                  d            d|j                  d      xs g d	|j                  d	      d
|j                  d
      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d      d|j                  d      ic S  i S )Nr   selectorLabelsprimarySelectorrootHexrangeHexsectionisCurrentRootr   fieldMapCountopcode07Countopcode08Countopcode09Countr!    opcode07SelectsCurrentRangeCountr"   opcode09StoresCurrentRangeCount'opcode08NearestCurrentRootProducerCount(opcode08NearestCurrentRangeProducerCountpromotingCandidateCount)rH   rb   r}   )selected_pointer_pathsrF   rL   s      r4   selected_pointer_path_forr      s    	%))*=>D" CGG$45x@!377+<#= #''*:";"Ar 3779- CGGJ/	
 3779-  cggo&>!? SWW[17R  !9  !9  !9  !9 2377;\3] 3CGG<^4_ 1#'':Z2[ 2377;\3]  :377=<!& ;CGG>=', *3773L+M- 4 Ir6   c                    | j                  d      rt        | j                  d            S | j                  d       d| j                  d       S )Nr&   r#   :r$   )rH   r^   )rL   s    r4   selector_labelr      sF    
www3777#$$gggq 122r6   c           
        |si S | xs g D ]~  }t        |      |k(  s||j                  d      |j                  d      |j                  d      xs g |j                  d      xs g |j                  d      |j                  d      dc S  i S )Nr%   rowPointerHexr   	linkedCnslinkedScanDepthlinkedScannedPointers)rF   r%   r   r   r   r   r   )r   rH   )save_scene_selectorsrF   rL   s      r4   static_selector_rowr      s    	#)r 
#(*$&)gg.B&C!$!9 WW[17R WW[17R#&77+<#=),1H)I 
 Ir6   c                   g }|s|S | xs g D ]  }|j                  d      |k7  r|j                  |j                  d      |j                  d      |j                  d      t        |j                  d            |j                  d      |j                  d      xs g |j                  d      |j                  d	      xs g d
        |S )Nr&   r'   r(   kindr)   
sceneIdHextilesetsdepthr*   )r'   r(   r   r)   r   r   r   r*   )rH   rg   r}   )save_scene_selector_refsrF   refsrL   s       r4   selector_resource_refsr      s     "$D'-2 777x'
+
+GGFO !89'',/
+1rWWW%wwy)/R	
 		 Kr6   c                ,     t         fddD              S )Nc              3  Z   K   | ]"  }t        j                  |      xs d        $ yw)r   NrI   rH   )r_   rW   selected_paths     r4   r`   z/current_path_candidate_count.<locals>.<genexpr>  s.       	Mc"'a(s   (+)r!   r   r"   r   r   r   r   )sum)r   s   `r4   current_path_candidate_countr     s     
  r6   c
           
        t        ||       }
t        |
|       }t        ||       }t        ||       }t	        ||       }|j                  d      xs; |j                  d      xs( |
j                  d      xs |j                  d      xs g }t        ||       }t        d |D              }t        d |D              }t        d |D              }t        d |D              }t        |D ch c].  }|j                  d      st        |j                  d            0 c}      }t        |      }t        |
j                  d            xs t        |v }t        |
j                  d            xs t        |v }t        | t        k(  xs! |xs |xs |xs |xs |j                  d	            }| t        k(  rd
}n'|s
|r|dk(  rd}n|r|s|s|s|t!        |      k(  rd}nd}i d| d|	d|d|d|r||z  nddt!        t#        ||             dt#        ||       d|j                  d      xs$ |j                  d      xs |j                  d      d|d| t        k(  d| t        t        hv d|d|d|
j                  d      xs g D cg c]4  }t%        |t&              r"|j                  d      r|j                  d      6 c}d|
j                  d      xs |d|j                  d      d |j                  d!      i d"|j                  d#      d$|j                  d%      d&|d't        |      d(t!        |      d)|d*t        |xr
 | xr |dk(        d+|d,|d d- d.|d/t!        |      d0|d1|d2|d3|d4t        |      d5|t        |j                  d	            |t)        | |      d6S c c}w c c}w )7Nr   c              3  D   K   | ]  }|j                  d       sd  yw)r   r   NrH   r_   rL   s     r4   r`   z+selector_runtime_context.<locals>.<genexpr>9  s     SScgg>Q6RqS     c              3  D   K   | ]  }|j                  d       sd  yw)r   r   Nr   r   s     r4   r`   z+selector_runtime_context.<locals>.<genexpr>:  s     ZAX9Y!Zr   c              3  D   K   | ]  }|j                  d       sd  yw)r   r   Nr   r   s     r4   r`   z+selector_runtime_context.<locals>.<genexpr>;  s     ^CSWWE\=]a^r   c              3  D   K   | ]  }|j                  d       sd  yw)r)   r   Nr   r   s     r4   r`   z+selector_runtime_context.<locals>.<genexpr><  s     &TSCGGN<Sq&Tr   r(   containsSourcecontainsTargetr    ,public-predecessor-target-side-non-promotingr   $resource-only-non-field-map-selector+non-route-field-map-selector-adjacency-onlyz%runtime-selector-context-unclassifiedrF   roler|   re   sampleShareobservedFileCountfileRowsr   r%   selectorEqualsTargetSelectorselectorInRoutePaircontainsSourceMapcontainsTargetMapaliasGroupSelectorsr   aliasGroupFieldMapsaliasRootHexaliasRootAddressOrderIndexrootAddressOrderIndexaliasSelectedPointerEntryHexselectedPointerEntryHexaliasFillCount	fillCountstaticSelectorRowstaticSelectorRowFoundresourceReferenceCountresourceSceneMatchedCountresourceOnlyresourceNamesresourceRefs   sceneAdjacencyRowssceneAdjacencyRowCount#sceneAdjacencySelectorOnlyPairCount$sceneAdjacencyStrictEventBackedCount(sceneAdjacencyConfirmedReviewBackedCountselectedPointerPathselectedPointerPathFound.selectedPointerPathSelectsOrStoresCurrentCount)r    routePromotionEvidenceFound
conclusion)rq   rt   r   r   r   rH   r   r   rT   r^   r   r}   
SOURCE_MAP
TARGET_MAPTARGET_SELECTORPUBLIC_PREDECESSOR_SELECTORr@   ri   rl   rS   selector_context_conclusion)rF   sample_counttotal_sample_countrh   rm   r~   r   r   r   r   rs   rp   r   
static_rowr   
field_mapsadjacency_rowsstrict_countconfirmed_countselector_only_countresource_scene_matched_countrL   resource_namesselected_path_current_countcontains_sourcecontains_targetroute_promotion_foundr|   s                               r4   selector_runtime_contextr      s    #>8<Kk8,E-.DhOM$%98DJ!":HED+& 	99[!	??;'	 >>+&	   */8DNSNSSLZ~ZZO^>^^#&&TD&T#T ]#Q[I\S!45]^N">}"M;??+;<=YzAYO;??+;<=YzAYO O# 	G	G	G 	G '		G
 "%%&EF ..GD%AQ%F?%3~#66F@*H** 	.* 	|	*
 	<N|&88TU* 	S!6uh!GH* 	)%:* 	=$$Y/o:>>BV3Wo[`[d[den[o* 	Z* 	'O(C* 	x,G+YY* 	_* 	_* 	"y17R 
#t$)< GGJ 
*& 	{{;Iz'*( 			),)** 	%eii0G&H+*, 	'		2K(L-*. 	%))K0/*0 	Z1*2 	!$z"23*4 	!#d)5*6 	$%A7*8 	TZ*nZ9UYZ9Z[9*: 	;*< 	Sb	=*> 	n?*@ 	!#n"5A*B 	./BC*D 	/E*F 	3OG*H 	}I*J 	#D$7K*L 	9:UM*N *..D.H.HIh.i)j'<1(NKS* *5 ^P 
s   (N7?N7	9N<c                >    |dk(  rd|  dS |dk(  rd|  dS |dk(  r	 yy)	Nr   z	Selector z resolves to non-scene CNS resource references with no field maps, so its runtime samples are menu/resource diagnostics, not map1_01a -> map2_02d route proof.r   z resolves to a different field-map alias group whose adjacency rows are selector-list metadata only and have no strict/confirmed route edge or current-root producer.r   zThe public predecessor selector 1:0 belongs to the target-side map set, but the observed runtime attempts never transition from it into selector 2:0/current root or the expected branch-state fill.zaThis selector context is retained as non-promoting until route/current execution evidence exists. )rF   r|   s     r4   r   r     sb    ??z "j j	
 FFz "l l	
 GGr	
 or6   c                L   t        |       }|j                  d      xs g }t        |      }|j                         D ci c]  \  }}|dvr|| }}}i dt	        | j                  t                    dt        |       d|j                  d      xs dd|j                  d      xs dd	|j                  d	      xs d
dt        |j                  d      xs d      dt        |j                  d      xs t        |            d|j                  d      xs t        |      d|j                  d      xs g d|j                  d      du d|j                  d      du d|j                  d      du dt        t        |j                                     dt        t        |j                                     dt        d |D              dt        d |D              dt        |d      t        |d      t        |d      |j                  d      xs ddS c c}}w ) NrJ   >   r
   r   r   r&   	objective promotionStatusunknowntargetSelectorr   re   r   sequenceCountobservedSelectorsobservedPublicSaveSelectorsanyReachedPublicSaveSelectorTanyReachedRouteSelectorContextanyReachedCurrentRootrd   nonRouteSelectorCountsr   c              3  X   K   | ]"  }t        |j                  d       xs d       $ yw)r   r   Nr   r   s     r4   r`   z!summarize_file.<locals>.<genexpr>  s%     $`TWS1H)I)NQ%O$`   (*r   c              3  X   K   | ]"  }t        |j                  d       xs d       $ yw)r   r   Nr   r   s     r4   r`   z!summarize_file.<locals>.<genexpr>  s%     "\PS3sww/D'E'J#K"\r   activeOrderValueCountsactiveOrder
activeSlotsecondaryBranchStater   )activeSlotDescriptorValueCountsbranchStateValueCountsr   )r5   rH   rN   rR   r^   relative_toROOTrD   rI   r@   rT   rS   r   r[   )r   datarJ   rK   rF   rG   non_route_countss          r4   summarize_filer
    sc   T?D88F!rDT"F  &||~He>) 	% 
D$$T*+T" 	TXXk*0b 	488$56C)	
 	$((#34= 	s488M27a8 	TXXo6C#d)D 	TXX&9:LfVn 	&txx0M'N'TRT 	'1O(PTX(X 	)$((3S*TX\*\ 	 *A!Bd!J 	$vflln56 	!$v.>.D.D.F'G"H 	 $`[_$`!`  	s"\W["\\!" 	!"4T="I#$ ,>dL+Q"4T;Q"Rhh|,2) s   H c                   |xs t        t              }|xs t        t              }|xs t        t              }|xs t        t              xs g }|xs t        t
              xs g }t        | j                  d            }|D cg c]  }t        |       }}t               }	t               }
t               }t               }|D ]R  }|	j                  |d          |
j                  |d          |j                  |d          |j                  |d          T t        d |D              }t        d |D              }t        d |D              }t        d	 |D              }t        |
j                         d
       D cg c]  \  }}t        |||||||||d
       }}}t        t        |	j                  t        d      |||||||d
      }i dddddt!        |      d|D cg c]  }|d   	 c}dt        dt"        dt$        ddddddd|dt'        d  |D              d!t'        d" |D              d#|d$|d%|d&t        d' |D              i d(t)        t        |	j                                     dt)        t        |
j                                     dt)        t        |j                                     dt)        t        |j                                     d)|r|d   d*   nd d+t!        |      d,t        d- |D              d.t        d/ |D              d0t'        d1 |D              d2|d3|d4g d5d6g d7d8t*        d9t!        t*              d:|d;d<S c c}w c c}}w c c}w )=Nz/runtime_selected_pointer_predecessor_*poll.jsonrd   r   r   r  c              3  &   K   | ]	  }|d      yw)r   Nr   r_   rM   s     r4   r`   z build_summary.<locals>.<genexpr>  s     "ST4(?#@"S   c              3  &   K   | ]	  }|d      yw)r   Nr   r  s     r4   r`   z build_summary.<locals>.<genexpr>  s      O&;!< Or  c              3  ,   K   | ]  }|d    s	d  yw)r   r   Nr   r  s     r4   r`   z build_summary.<locals>.<genexpr>  s     (etEc@d(es   
c              3  &   K   | ]	  }|d      yw)re   Nr   r  s     r4   r`   z build_summary.<locals>.<genexpr>  s     CTT-0Cr  c                    | d    | d   fS )Nr   r   r   )rM   s    r4   <lambda>zbuild_summary.<locals>.<lambda>  s    tAwhQ0 r6   )rW   zobserved-non-route-selectorr   zpublic-predecessor-selectorrv   z)runtime predecessor route attempt contextsourcePatternr   sourceFileCountsourceFilesr   publicPredecessorSelectorr   currentRootHexr   blocked
proofFoundF!predecessorRouteAttemptProofFound"publicPredecessorObservedFileCountr   c              3  &   K   | ]	  }|d      yw)r   Nr   r  s     r4   r`   z build_summary.<locals>.<genexpr>  s     -gY]d3S.T-gr  r   c              3  &   K   | ]	  }|d      yw)r   Nr   r  s     r4   r`   z build_summary.<locals>.<genexpr>  s     $UtT*A%B$Ur  r   r   totalSampleCounttotalSequenceCountc              3  &   K   | ]	  }|d      yw)r   Nr   r  s     r4   r`   z build_summary.<locals>.<genexpr>  s     !JD$"7!Jr  observedSelectorCountsdominantDiversionSelectorrF   diversionSelectorContextCountfieldMapDiversionSelectorCountc              3  D   K   | ]  }|j                  d       sd  yw)r   r   Nr   r   s     r4   r`   z build_summary.<locals>.<genexpr>
  s       .
sww{/CA.
r   "resourceOnlyDiversionSelectorCountc              3  D   K   | ]  }|j                  d       sd  yw)r   r   Nr   r   s     r4   r`   z build_summary.<locals>.<genexpr>  s       2
sww~/FA2
r   $diversionRoutePromotionEvidenceFoundc              3  >   K   | ]  }|j                  d         yw)r   Nr   r   s     r4   r`   z build_summary.<locals>.<genexpr>  s      4
7:CGG124
s   diversionSelectorContexts publicPredecessorSelectorContext$failedPredecessorRouteAttemptGateIds)zroute-selector-2-0-observationzcurrent-root-observationz)predecessor-to-current-runtime-transitionzstrict-source-hotspotmissingEvidence)zMruntime observation that public predecessor selector 1:0 reaches selector 2:0zIruntime observation that selected pointer becomes current root 0x00540714zNcontrol-flow proof that predecessor route attempts select the current 2:0 rootz<strict map1_01a source hotspot or equivalent runtime triggerevidenceRefsevidenceRefCountrh   r   aJ  Existing predecessor-save route-attempt polls observe the public predecessor selector in some runs, but none reach selector 2:0 or current root 0x00540714. Observed diversions such as 19:1 and 50:0 remain non-route diagnostics, so predecessor runtime attempts do not replace selected-root execution or strict-source-hotspot proof.)r9   MAPSET_ALIASESSCENE_ADJACENCY_INDEXGLOBAL_SELECTED_POINTER_PATHSSAVE_SCENE_SELECTORSSAVE_SCENE_SELECTOR_REFSrT   globr
  r   updater   rR   r   r   rH   r@   r   CURRENT_ROOT_HEXra   rS   EVIDENCE_REFS)out_dirrm   r~   r   r   r   pathsr   rh   selector_totalsnon_route_totalsactive_order_totalsbranch_state_totalsrM   route_selector_hit_countcurrent_root_hit_countpublic_selector_observed_countr   rF   rG   diversion_contextspublic_predecessor_contexts                         r4   build_summaryrE    s    $I'9.'IN%R);<Q)RO3h7IJg7h/a3EFZ3[a_a7m;MNf;gmkm7<< QRSE.34d^D!4E4$+IO%,Y(/	(/	 Ct$456%= >?""4(@#AB""4(@#AB	C
  #"SU"SS  O OO%((eu(e%e"CUCC  &""$0 
 He 	!" $)	
 $ ":#7; %"8=8N8 	3u:8 	7V7	8
 	$%@8 	/8 	*8 	98 	e8 	,U8 	-.L8 	)#-gaf-g*g8 	 $Uu$U!U8 	 !98 	58  	.!8" 	c!JE!JJ#8$ 	!$vo.C.C.E'F"G%8& 	!$v.>.D.D.F'G"H'8( 	!$v.A.G.G.I'J"K)8* 	!$v.A.G.G.I'J"K+8, 	$J\%7%::%Fbf-8. 	(-?)@/80 	)# .
+.
 +
186 	-c 2
+2
 /
78< 	/ 4
>P4
 1
=8B 	$%7C8D 	+,FE8F 	/ 1
G8R 	 
S8^ 	_8` 	C.a8b 	c8d 	Fg8 8Y 5D 8s   M% M*%M0c                F   | j                  d      xs g }| j                  d      xs i }dd| d   dddd| d    d	| d
    d| d    d| d    d| d    d| d    d| j                  d       dd| j                  d       d| j                  d       d| j                  d       dd| j                  d       d| d     dd!| d"    dd#| d$    ddd%dd&d'g}| d(   j                         D ]  \  }}|j                  d)| d*| d+        |j                  g d,       |D ]  }d-j	                  |j                  d.      xs g       }d-j	                  |j                  d/      xs g d d0       }|xs |xs d1}	|j                  d2|j                  d3       d4|j                  d5       d6|j                  d7       d8|j                  d9       d4|	 d6|j                  d:       d|j                  d;       d|j                  d<       d*|j                  d=       d*|j                  d>       d+        |j                  dd?dd@|j                  d3       ddA|j                  d5       ddB|j                  d7       dCd-j	                  |j                  d.      xs g       xs d1 ddD|j                  d=       dE|j                  d>       d|j                  d      xs dg       |j                  g dF       | dG   D ]  }d-j	                  dH |dI   j                         D              xs d1}
|j                  d2|dJ    d6|
 d*t        |dK         j                          d*|d    d*|d    d*|d7    d*|dL    d+        |j                  g dM       | dN   D ]  }|j                  dO|         |j                  g dP       | dQ   D ]>  }|j                  dR|dJ    dSd-j	                  |j                  dT      xs g               @ dUj	                  |      dUz   S )VNr+  r,  z+# Runtime Predecessor Route Attempt Contextr   r   z
## Summaryz- source files: r  z- total sequences/samples: r   /r  z1- public predecessor selector observed in files: r  z- route selector hit count: r   z- current root hit count: r   z - dominant diversion selector: `r#  `z- diversion contexts: r$   (field-map r%  , resource-only r'  )z,- diversion route promotion evidence found: r)  z- proof found: `r  z*- predecessor route attempt proof found: `r  z- promotion status: `r   z## Selector Countsz| selector | samples |z| --- | ---: |r"  z| z | z |)r   z## Diversion Selector Contextsr   zz| selector | classification | samples | root | maps/resources | adjacency/strict/confirmed | current proof | route proof |z3| --- | --- | ---: | --- | --- | --- | ---: | --- |, r   r      r<   z| `rF   z` | `r|   z` | re   z | `r   r   r   r   r   r   z## Public Predecessor Selectorz- selector: `z- classification: `z- samples: z- field maps: `z- current proof count: z"- route promotion evidence found: )r   z## Filesr   zR| file | selectors | public 1:0 | route 2:0 | current root | samples | sequences |z0| --- | --- | ---: | ---: | ---: | ---: | ---: |rh   c              3  0   K   | ]  \  }}| d |   ywr   Nr   r_   rW   rY   s      r4   r`   zmarkdown.<locals>.<genexpr>{  s     `:3Qug.`   rd   r   r   r   )r   z## Missing Evidencer   r.  z- )r   z## Evidence Refsr   r/  z- `z`: r   
)rH   rR   rg   extendjoinr^   lower)summaryrC  public_contextlinesrF   rG   rM   maps	resourcesmaps_or_resourcesr   refs               r4   markdownr]  -  s    %@AGR[[!CDJN5



7#4567
%g.B&C%DAgN`FaEbc
;GDh<i;jk
&w/F'G&HI
$W-B%C$DE
*7;;7R+S*TTUV
 -L!M N Okk"BCD E %IJK1	N 7w{{Ci7j6kl
7<013
4W=`5a4bbcd
(9 :;1=

 1E4 ##;<BBD 2%r(3ugR012	LL	
 # 
yy+.4"5IItxx8>BCD	 4I4$((:&'uTXX6F-G,HTXXVcMdLe f#$E*;)<Dxx012!xx>?@xxBCDCxxHIJ#xx567r;	
	
 
LL,N..z:;1=!."4"45E"F!GqI.,,];<=dii(:(:;(G(M2NURUVVWX%n&8&89i&j%kl01C1CDa1b0cd|,2	
 
LL	
   
II`FVAWA]A]A_``gdg	$v,tI;c4678>>@A+,-S6K1L0MSM"#3tO'<&=RA	

 
LL	
 )* "r$[!"	LL-.~& Qs3v;-s499SWWX5F5L"+M*NOPQ99Ud""r6   c           
         dj                  d | d   j                         D              }dj                  d | d   D              }dj                  d | j                  d      xs g D              }dj                  d	 | d
   D              }dj                  d | d   D              }| j                  d      xs i }dj                  g dt        j                  | d          d| d    d| d    d| d    d| d    d| d    d| d    dt        j                  t        | j                  d                   d| j                  d       d | j                  d!       d"| j                  d#       d$t        | j                  d%            j                          d&| d'    d(| d)    d*t        j                  | d+          d,| d-| d.t        j                  t        |j                  d/                   d0t        j                  t        |j                  d1                   d2|j                  d3       d4t        j                  d5j                  |j                  d6      xs g       xs d7       d8|j                  d9       d:t        |j                  d;            j                          d<t        j                  |j                  d      xs d       d=| d>| d?| d@      S )ANrR  c              3  Z   K   | ]#  \  }}d t        j                  |       d| d % yw)<tr><td>	</td><td>
</td></tr>Nhtmlescape)r_   rF   rG   s      r4   r`   zhtml_page.<locals>.<genexpr>  s5      He 4;;x()5'Ds   )+r"  c              3  @  K   | ]  }d t        j                  |d          dt        j                  dj                  d |d   j                         D              xs d       dt	        |d         j                          d|d    d|d	    d|d
    d|d    d  yw)r`  r   ra  rL  c              3  0   K   | ]  \  }}| d |   ywrO  r   rP  s      r4   r`   z&html_page.<locals>.<genexpr>.<genexpr>  s     $g*#uuAeW%5$grQ  rd   r<   r   r   r   re   r   rb  N)rd  re  rT  rR   r^   rU  r  s     r4   r`   zhtml_page.<locals>.<genexpr>  s       	{{4<() *{{499$gM]H^HdHdHf$ggnknop q4678>>@A B+,- .)*+ ,M"# $O$% &	s   BBrh   c              3    K   | ]g  }d t        j                  t        |j                  d                   dt        j                  t        |j                  d                   d|j                  d       dt        j                  t        |j                  d                   dt        j                  dj	                  |j                  d      xs |j                  d      xs g d	d
       xs d       d|j                  d       d|j                  d       d|j                  d       d|j                  d       dt        |j                  d            j                          d j y	w)r`  rF   ra  r|   re   r   rL  r   r   NrM  r<   r   rG  r   r   r   r   rb  )rd  re  r^   rH   rT  rU  r  s     r4   r`   zhtml_page.<locals>.<genexpr>  sX      	{{3txx
3456 7{{3txx(89:;< =xx&' ({{3txx	2345 6{{499TXXk%:%ctxx?X?^\^`bab>cdkhklm nxx012!88:;
<A88>?
@ AxxHIJ K4889:;AACD E	s   E.E0r+  r   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li></li>Nrc  r  s     r4   r`   zhtml_page.<locals>.<genexpr>  s#     ]$T[[./u5]s   #%r.  c              3     K   | ]X  }d t        j                  |d          dt        j                  dj                  |j                  d      xs g              d Z yw)z
<li><code>r   z	</code>: rL  r   rj  N)rd  re  rT  rH   )r_   r\  s     r4   r`   zhtml_page.<locals>.<genexpr>  sY       T[[V-.iDIIcggV^N_NeceDf8g7hhmns   AA r/  r,  a=  <!doctype html>
<html lang="ko">
<head>
  <meta charset="utf-8">
  <title>Runtime Predecessor Route Attempt Context</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 24px; line-height: 1.5; color: #202124; }
    table { border-collapse: collapse; width: 100%; margin: 16px 0 28px; }
    th, td { border: 1px solid #d7dce2; padding: 6px 8px; text-align: left; vertical-align: top; }
    th { background: #f4f6f8; }
    code { background: #f4f6f8; padding: 1px 4px; }
  </style>
</head>
<body>
  <h1>Runtime Predecessor Route Attempt Context</h1>
  <p>r   z5</p>
  <h2>Summary</h2>
  <ul>
    <li>source files: r  z'</li>
    <li>total sequences/samples: r   rG  r  z=</li>
    <li>public predecessor selector observed in files: r  z(</li>
    <li>route selector hit count: r   z&</li>
    <li>current root hit count: r   z1</li>
    <li>dominant diversion selector: <code>r#  z)</code></li>
    <li>diversion contexts: r$  rI  r%  rJ  r'  z9)</li>
    <li>diversion route promotion evidence found: r)  z!</li>
    <li>proof found: <code>r  zB</code></li>
    <li>predecessor route attempt proof found: <code>r  z-</code></li>
    <li>promotion status: <code>r   zy</code></li>
  </ul>
  <h2>Selector Counts</h2>
  <table><thead><tr><th>selector</th><th>samples</th></tr></thead><tbody>a	  </tbody></table>
  <h2>Diversion Selector Contexts</h2>
  <table><thead><tr><th>selector</th><th>classification</th><th>samples</th><th>root</th><th>maps/resources</th><th>adjacency/strict/confirmed</th><th>current proof</th><th>route proof</th></tr></thead><tbody>zW</tbody></table>
  <h2>Public Predecessor Selector</h2>
  <ul>
    <li>selector: <code>rF   z+</code></li>
    <li>classification: <code>r|   z</code></li>
    <li>samples: re   z </li>
    <li>field maps: <code>rL  r   r<   z*</code></li>
    <li>current proof count: r   z.</li>
    <li>route promotion evidence found: r   z</li>
  </ul>
  <p>z</p>
  <h2>Files</h2>
  <table><thead><tr><th>file</th><th>selectors</th><th>public 1:0</th><th>route 2:0</th><th>current root</th><th>samples</th><th>sequences</th></tr></thead><tbody>z3</tbody></table>
  <h2>Missing Evidence</h2>
  <ul>z%</ul>
  <h2>Evidence Refs</h2>
  <ul>z</ul>
</body>
</html>
)rT  rR   rH   rd  re  r^   rU  )rV  selector_rows	file_rowsdiversion_rowsmissingr   rW  s          r4   	html_pagerp    s   II &'?@FFH M 		  G$ I YY  KK ;<B N gg]'J[B\]]G77 >* D [[!CDJN4 4  4 kk','()4*4$ 012%4$3"%4& #**>"?!@'4& AB'4& CJJ\B]A^'4&_8'4( 9@@d8e7f)4(g#)4* $++B#C"D+4*E!+4, "))>!? @-4,A,-4. -1KKGKKHc<d8e,f+g/4.h/40 %[[)HIJ140 KW140 X_WbWb  dD  XE  WF140 FV140 W^  Wb  Wb  cG  WH  VI140I3142 47w{{Ci7j3k3q3q3s2t342u344 $L1254436546 7>>a6b5c746d!748 "&W5F-G!H I948JJ94> KX?4>YR?4B Sa  RbC4BbC4H S););J)G%HIJI4HKI4J  ${{3~/A/ABR/S+TUVK4JWK4L !$$]34M4L5M4N  ;;tyy1C1CK1P1VTV'W'^[^_`O4NaO4P -001abcQ4Pd)Q4R *-^-?-?@]-^)_)e)e)g(hS4RiS4V kk.$$\28b9:W4V;dW4Z en  do[4Zo[4^ i_4^_4b fc4bc4 4r6   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |:|j                  j                  dd       |j                  t        |       d	       y y )
NT)parentsexist_ok.runtime_predecessor_route_attempt_context.jsonF   )ensure_asciiindentrR  r-   r.   )mkdir
write_textr0   dumpsparentrp  )rV  r:  html_outs      r4   write_outputsr}    s    MM$M.??KK

7q9D@ L  dT:Ig.A r6   c                 X   t        j                         } | j                  dt        t               | j                  dt        d d       | j                         }t        |j                        }t        ||j                  |j                         t        d|j                  dz          y )Nz	--out-dir)typedefaultz
--html-outzHOptional HTML review path. By default only the JSON evidence is written.)r  r  helpz3wrote runtime predecessor route attempt context -> rt  )argparseArgumentParseradd_argumentr   OUT
parse_argsrE  r:  r}  r|  print)parserargsrV  s      r4   mainr    s    $$&F
$<
W	   DDLL)G'4<<7	?O@  @A  B  Cr6   __main__)r   r   returndict[str, Any])r   r   r  r   )r   r   r  r^   )rJ   list[dict[str, Any]]r  zCounter[str])rJ   r  rU   r^   r  zdict[str, int])rX   zlist[Any] | NonerF   
str | Noner  r}   )rh   r  rF   r^   r  r  )rm   r  rF   r  r  r  )rs   r  rF   r  r  r  )r~   r  rF   r  r  r  )r   r  rF   r  r  r  )rL   r  r  r^   )r   r  rF   r  r  r  )r   r  rF   r  r  r  )r   r  r  rI   )rF   r^   r   rI   r   rI   rh   r  rm   r  r~   r  r   r  r   r  r   r  r   r^   r  r  )rF   r^   r|   r^   r  r^   )r:  r   rm   dict[str, Any] | Noner~   r  r   r  r   list[dict[str, Any]] | Noner   r  r  r  )rV  r  r  r^   )rV  r  r:  r   r|  zPath | Noner  None)r  r  )6__doc__
__future__r   r  rd  r0   collectionsr   pathlibr   typingr   __file__resolverr  r  r  r?   rB   r1  r2  r3  r4  r5  r   r   r8  r   r   r9  r5   r9   rD   rN   r[   rb   ri   rq   rt   r   r   r   r   r   r   r   r   r
  rE  r]  rp  r}  r  __name__r   r6   r4   <module>r     s   8 "       H~''*
Ul	0	::HH  #&X X 88 !FF #  

 F
 8
 ?
	 G
 0
 :
	_9x8Q"(A"( *    F3"2 .aaa a  	a
 #a $a +a /a 3a a aHo&D ,0-1488<<@rr)r +r 2	r
 6r :r rja#HZz <?X\ BC zF r6   