
    JjX                    J   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	  ee
      j                         j                  d   Zedz  Zdd	ed
z  dddddedz  dddddedz  dddddedz  dddddedz  ddddded z  d!ddd"d#ed$z  d%d&dgZg d'Zg d(Zg d)Zd*g d+d,d-g d+d,d.g d+d,d/g d0d,d1g d2d,d3g d4d,d5g d6d,gZdGd7ZdHd8ZdId9ZdJd:ZdKd;ZdLd<ZdMd=ZdNd>ZdOd?ZdPd@Z	 	 dQ	 	 	 	 	 dRdAZdSdBZdSdCZ edf	 	 	 	 	 	 	 dTdDZ!dUdEZ"e#dFk(  r e"        yy)VzHSummarize runtime opcode24 flag/source observations across route probes.    )annotationsN)Path)Any   out
routeWatchruntime_route_watch_values_pollz$runtime_route_watch_values_poll.jsonzmenu route-watch pollF)keysourcepathkindconstructedDiagnosticsourceAdaptive=runtime_selected_pointer_source_exit_adaptive_coordinate_pollzBruntime_selected_pointer_source_exit_adaptive_coordinate_poll.jsonz-public source-save camera-start adaptive exitsourceTrailStart>runtime_selected_pointer_source_exit_adaptive_trail_start_pollzCruntime_selected_pointer_source_exit_adaptive_trail_start_poll.jsonz,public source-save trail-start adaptive exitsourceExitLoadConfirmedEruntime_selected_pointer_source_exit_branch_state_load_confirmed_pollzJruntime_selected_pointer_source_exit_branch_state_load_confirmed_poll.jsonz,public source-save load-confirmed exit pathspredecessorDirectionSweep9runtime_selected_pointer_predecessor_direction_sweep_pollz>runtime_selected_pointer_predecessor_direction_sweep_poll.jsonz"public predecessor direction sweeppredecessorLeftActivationGruntime_selected_pointer_predecessor_left_overrun_activation_sweep_pollzLruntime_selected_pointer_predecessor_left_overrun_activation_sweep_poll.jsonz0public predecessor left-overrun activation sweeppatchedSelectorDiagnosticOruntime_selected_pointer_patched_public_selector_2_0_input_path_case_alias_pollzTruntime_selected_pointer_patched_public_selector_2_0_input_path_case_alias_poll.jsonz#constructed selector 2:0 diagnosticT)opcode24Mode1Sourceopcode24RuntimeFlagopcode24CurrentObjectIndex)zmode1-source-runtime-producerzruntime-flag-route-contextzselected-root-execution-proofz$source-save-route-promotion-evidencez,strict-hotspot-or-equivalent-runtime-trigger)zSruntime producer setting opcode24 mode1 source 0x0059e348 nonzero on the route pathzUruntime flag 0x0059e34d == 0x01 observed in a selector 2:0/current-root route contextzFselected-root execution proof for 0x00540714 before opcode24 route usezPsource-save load path reaching route/current selector instead of diversion 48:13z5strict map1_01a hotspot or equivalent runtime triggerz(out/runtime_route_watch_values_poll.json)observedSelectorsobservedWatchValuessampleCount)r   fieldszNout/runtime_selected_pointer_source_exit_branch_state_load_confirmed_poll.jsonzBout/runtime_selected_pointer_predecessor_direction_sweep_poll.jsonzXout/runtime_selected_pointer_patched_public_selector_2_0_input_path_case_alias_poll.json)r   r   anyReachedRouteSelectorContextz1out/runtime_source_save_load_variant_context.json)classificationreadyPathSummarydiversionSelectorContextroutePromotionEvidenceFoundz5out/save_selector_opcode24_mode1_runtime_context.json)
proofFound$failedOpcode24RuntimeProducerGateIdsmissingEvidenceevidenceRefsz7out/save_selector_opcode24_runtime_enabled_context.json)r'   #failedOpcode24RuntimeEnabledGateIdsr)   r*   c                p    | j                         si S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)r   s    D/home/exedev/hwanse/tools/summarize_runtime_opcode24_flag_context.py	load_jsonr5      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     r4   	<genexpr>zlist_text.<locals>.<genexpr>   s     95CJ9s   -join)valuess    r4   	list_textrB      s     889FLb99@S@r6   c                B    dj                  d | xs g D              xs dS )Nr8   c              3  f   K   | ])  }|j                  d        d|j                  d        + yw)valueHexxcountNgetr;   rows     r4   r=   z"value_rows_text.<locals>.<genexpr>   s/     VCswwz*+1SWWW-=,>?Vs   /1r>   r?   rowss    r4   value_rows_textrN      s"    88V4:SUVV]Z]]r6   c                .    t        d | xs g D              S )Nc              3  B   K   | ]  }|j                  d       dv  yw)rE   >   N0x000x0000
0x00000000NrH   rJ   s     r4   r=   z%value_rows_nonzero.<locals>.<genexpr>   s      gUXswwz"*PPgs   )anyrL   s    r4   value_rows_nonzerorU      s    g\`\fdfgggr6   c                4    t        fd| xs g D              S )Nc              3     K   | ]7  }|j                  d       k(  st        |j                  d      xs d       9 yw)rE   rG   r   N)rI   int)r;   rK   	value_hexs     r4   r=   zcount_value.<locals>.<genexpr>   s5     dc377:CVZcCcs3777#(q)ds
   A #A )sum)rM   rY   s    `r4   count_valuer[      s    dTZRdddr6   c                   | j                  d      xs i j                  |      }||S i }| j                  d      xs g D ]w  }|j                  d      xs i j                  |      xs g D ]J  }|j                  d      }||j                  |d      t        |j                  d      xs d      z   ||<   L y t        |j                         d       D cg c]
  \  }}||d	 c}}S c c}}w )
Nr   rM   uniqueWatchValuesrE   r   rG   c                    | d    | d   fS )Nr   r    )items    r4   <lambda>z(aggregate_watch_values.<locals>.<lambda>   s    $q'SWXYSZH[ r6   )r
   )rE   rG   )rI   rX   sorteditems)datar
   topcountsrK   	value_rowrY   rG   s           r4   aggregate_watch_valuesrh      s    88)*0b
5
5c
:C

Fxx%2 \77#67=2BB3GM2 	\I!j1I  &

9a 83y}}W?U?ZYZ;[ [F9		\\ !'v||~;[ \Iu /  s   C,c                    g }| j                  d      xs g D ]B  }t        |t              r|j                  d      n
t        |      }|s2|j	                  |       D |S )NuniqueSelectorContextsselector)rI   
isinstancedictr:   append)rK   	selectorsr`   rk   s       r4   selector_listrp      s[    I017R '+5dD+A488J's4yX&' r6   c                   g }| j                  d      xs g D ]  }|j                  d      xs i }|j                  |j                  d      |j                  d      t        |      |j                  d      |j                  d      |j                  d      |j                  d      xs g |j                  d	      xs g |j                  d
      xs g d	        |S )NrM   r]   namer    sourceReadyrouteSelectorHitCountcurrentRootHitCountr   r   r   )	rr   r    ro   rs   rt   ru   mode1SourceValuesruntimeFlagValuescurrentObjectIndexValues)rI   rn   rp   )rd   rM   rK   watch_valuess       r4   compact_rowsrz      s    Dxx%2 ww239rGGFO77=1&s+77=1%(WW-D%E#&77+@#A!-!1!12G!H!NB!-!1!12G!H!NB(4(8(89U(V(\Z\

 
	 Kr6   c                <   t         D ci c]  }|t        ||       }}t        |d   d      }i d| d   d| d   d| d   d| d   d|j                  d      d|j                  d      d	|j                  d	      xs g d
|j                  d
      dt	        |j                  d            dt	        |j                  d            d|d   d|d   d|d   dt        |d         dt        |d         d|dt        |d         dt        |      iS c c}w )Nr   0x01r
   r   r   r   r    sequenceCountr   sourceReadyCountr"   anyReachedCurrentRootrv   r   rw   rx   r   mode1SourceNonzeroObservedruntimeFlagNonzeroObservedruntimeFlagOneCount!currentObjectIndexNonzeroObservedrM   )
WATCH_KEYSrh   r[   rI   boolrU   rz   )configrd   r
   watchesruntime_flag_one_counts        r4   summarize_pollr      s   AKL#s*455LGL(1F)GPve}&" 	v 	 (?!@	
 	txx. 	/2 	TXX&9:@b 	DHH%78 	)$txx8X/Y*Z 	 dhh/F&G!H 	W%:; 	W%:; 	#G,H$I 	%&8AV9W&X 	%&8AV9W&X  	5!" 	,-?Hd@e-f#$ 	T"%  Ms   Dc                   | xs i } | sddiS | j                  d      xs i }| j                  d      xs i }i ddd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      d|j                  d      d|j                  d      xs g d|j                  d      d|j                  d      d|j                  d      |j                  d      |j                  d      |j                  d       |j                  d!      |j                  d"      |j                  d#      xs i j                  d$      |j                  d%      |j                  d&      |j                  d      d'	S )(N	availableFr$   r%   TsourceArtifact-runtime_source_save_load_variant_context.jsonr#   promotionStatusstrictSourceHotspotProofFoundselectedRootExecutionProofFoundr&    readyPathDiversionClassificationdiversionClassificationreadyPathCountreadyPathRouteOrCurrentCountrouteOrCurrentReadyPathCount readyPathCandidateOrOutsideCount candidateOrOutsideReadyPathCount!readyPathDominantNonRouteSelectordominantNonRouteSelectordiversionSelectorrk   diversionFieldMaps	fieldMapsdiversionSelectorInRoutePairselectorInRoutePairdiversionContainsSourceMapcontainsSourceMapcontainsTargetMapsceneAdjacencyRowCount#sceneAdjacencySelectorOnlyPairCount$sceneAdjacencyStrictEventBackedCount(sceneAdjacencyConfirmedReviewBackedCountselectedPointerPathrootHex.selectedPointerPathSelectsOrStoresCurrentCountselectedRootExecutionRefFound)	diversionContainsTargetMapdiversionSceneAdjacencyRowCount,diversionSceneAdjacencySelectorOnlyPairCount-diversionSceneAdjacencyStrictEventBackedCount1diversionSceneAdjacencyConfirmedReviewBackedCountdiversionSelectedPointerRootHex)diversionSelectedPointerCurrentProofCount&diversionSelectedRootExecutionRefFound$diversionRoutePromotionEvidenceFoundrH   )contextready	diversions      r4   build_source_save_load_contextr      sR   mGU##KK*+1rE67=2I%T%I% 	'++&67% 	7;;'89	%
 	(5T)U% 	*7;;7X+Y% 	&w{{3P'Q% 	+EII6O,P% 	%))$45% 	'		2P(Q% 	+EII6X,Y% 	,UYY7Q-R% 	Y]]:6% 	immK8>B% 	"9==1A#B%  	'	6K(L!%" 	%imm4G&H#%$ '0mm4G&H+4==9Q+R8A19
 :C2:
 >G]]6>
 -6MM:O,P,VTV+[+[,
 6?]]<6
 3<--@_2`09>[0\I% %r6   c           
        | xs t         }||nt        t        dz        }|D cg c]-  }|d   j                         rt	        |t        |d               / }}t        |      }|D cg c]  }|j                  d      r| }}t        d |D              }t        d |D              }	t        d |D              }
t        d |D              }t        d |D              }|rd	}n|
rd
}n|rd}nd}|d	k(  }d}i ddddd|d|d	k7  rdndd|d|d|rg nt        d|rg nt        dt        dt        t              dt        |      d|d|	d|
d |d!|d"t        d# |D              i d$|d%|d&|d'|j                  d      d(|j                  d      d)|j                  d*      d+|j                  d,      d-|j                  d.      d/|j                  d0      d1|j                  d2      d3|j                  d4      d5|j                  d6      d7|j                  d8      xs g d9|j                  d:      d;|j                  d<      d=|j                  d%      d>|d?|iS c c}w c c}w )@Nr   r   r   c              3  d   K   | ](  }|j                  d       xs |j                  d       * yw)r"   r   NrH   r;   polls     r4   r=   z build_summary.<locals>.<genexpr>$  s4       	12Wdhh?V6WWs   .0c              3     K   | ];  }|j                  d       xs |j                  d      xr |j                  d       = yw)r"   r   r   NrH   r   s     r4   r=   z build_summary.<locals>.<genexpr>(  sJ         
2	3	Xtxx@W7X 	.HH,-	. s   AAc              3  >   K   | ]  }|j                  d         yw)r   NrH   r   s     r4   r=   z build_summary.<locals>.<genexpr>-  s     Q4!=>Q   c              3  >   K   | ]  }|j                  d         yw)r   NrH   r   s     r4   r=   z build_summary.<locals>.<genexpr>.  s     P$txx <=Pr   c              3  X   K   | ]"  }t        |j                  d       xs d       $ yw)r   r   N)rX   rI   r   s     r4   r=   z build_summary.<locals>.<genexpr>/  s$     UtTXX&;<ABUs   (*zreal-route-observedzmode1-source-nonzero-observedz runtime-flag-nonroute-mode1-zerozopcode24-watch-all-zeroaY  Runtime opcode24 watch samples do not provide selected-root execution proof. The runtime flag reaches 0x01 only in the menu route-watch poll, where selectors are 8:0/50:0 and opcode24 mode1 source plus current object index stay 0x00. Public source/predecessor probes, including the load-confirmed source-exit paths, and the constructed selector 2:0 diagnostic also keep opcode24 mode1 source at 0x00. The source-save load context also diverts through a non-route selector before exit candidates. The next useful proof target remains a real runtime producer for 0x0059e348 or a strict map1_01a hotspot.r   map1_01atargetmap2_02dr#   r   blocked	candidater'   runtimeOpcode24FlagProofFound failedRuntimeOpcode24FlagGateIdsr)   r*   evidenceRefCount	pollCountrealRouteHitObservedconstructedRouteHitObservedr   r   r   r   c              3  >   K   | ]  }|j                  d         yw)r   NrH   r   s     r4   r=   z build_summary.<locals>.<genexpr>T  s     0qcg:]1^0qr   r   r&   sourceSaveLoadContextsourceSaveLoadClassificationsourceSaveLoadPromotionStatus.sourceSaveLoadReadyPathDiversionClassificationr   sourceSaveLoadReadyPathCountr   *sourceSaveLoadReadyPathRouteOrCurrentCountr   .sourceSaveLoadReadyPathCandidateOrOutsideCountr   /sourceSaveLoadReadyPathDominantNonRouteSelectorr   %sourceSaveLoadDiversionClassificationr   sourceSaveLoadDiversionSelectorr    sourceSaveLoadDiversionFieldMapsr   7sourceSaveLoadDiversionSelectedPointerCurrentProofCountr   2sourceSaveLoadDiversionRoutePromotionEvidenceFoundr   )sourceSaveLoadRoutePromotionEvidenceFoundpolls
conclusion)INPUTSr5   OUTr0   r   r   rI   rT   rZ   %RUNTIME_OPCODE24_FLAG_FAILED_GATE_IDS&RUNTIME_OPCODE24_FLAG_MISSING_EVIDENCE#RUNTIME_OPCODE24_FLAG_EVIDENCE_REFSlen)inputs source_save_load_variant_contextconfigsr   r   source_save_contextr   
real_pollsreal_route_hitconstructed_route_hitmode1_nonzeroflag_nonzeroflag_one_countr#   proof_foundr   s                   r4   build_summaryr     s    G ,7 	)sLLM % &>  " 	vy89E 
 99YZ#(R49P0Q$RJR  N       
 Q5QQMP%PPLUuUUN.	8	;2 $99K	t 6*6*6 	.6 	:O(O9U`	6
 	k6 	(6 	+B#H6 	22X6 	;6 	C CD6 	SZ6 	6 	&'<6  	%m!6" 	%l#6$ 	~%6& 	,S0qkp0q-q'6( 	*>)6* 	&~+6, 	 !4-6. 	'(;(?(?@P(Q/60 	()<)@)@AR)S162 	9:M:Q:Q.;
368 	'(;(?(?@P(Q96: 	56I6M6M*7
;6@ 	9:M:Q:Q.;
A6F 	:;N;R;R/<
G6L 	01D1H1H%2
M6R 	*+>+B+BCV+WS6T 	+,?,C,CDX,Y,_]_U6V 	BCVCZCZ7D
W6\ 	=>Q>U>U2?
]6b 	45H5L5L)6
c6h 	i6j 	jk6 6I Ss   2I-(I2?I2c                X
   g ddd| j                  d       d| j                  d       dd| j                  d	       dd
| j                  d       dd| j                  d       d| j                  d       d| j                  d       dd| j                  d       d| j                  d       d| j                  d       d| j                  d       d| j                  d       dd| j                  d       dd| j                  d        d!t        | j                  d"             dd#| j                  d$       d%| j                  d&       d%| j                  d'       d(| j                  d)       d*| j                  d+       d,| j                  d-       d.| j                  d/       d0d1j                  | j                  d2      xs g        dd3t        | j                  d4      xs g        d5| j                  d6       d| j                  d7      xs ddd8d| j                  d4      xs g D cg c]  }d9| 	 c}dd:dd;d<| j                  d=      xs g D cg c]@  }d>|j                  d?       d@dAj                  |j                  dB      xs g       xs dC dDB c}ddEdF}| j                  dG      xs g D ]  }|j                  dH      rdIn|j                  dJ      }|j	                  d>|j                  d       d@|j                  dK       dLt        |j                  dM             d@|j                  dN       dO|j                  dP       dLt        |j                  dQ             dRt        |j                  dS             dRt        |j                  dT             d@| dD        |j                  g dU       | j                  dG      xs g D ]  }|j                  dV      xs g D ]  }|j	                  d>|j                  d       dR|j                  dW       d@|j                  dX       dY|j                  dK       dLt        |j                  dZ             d@|j                  d[       dO|j                  d\       dLt        |j                  dQ             dRt        |j                  dS             dRt        |j                  dT             d]        
 d^j                  |      d^z   S c c}w c c}w )_Nz# Runtime Opcode24 Flag Context z
- route: `r   z` -> `r   `z- classification: `r#   z- promotion status: `r   z- poll count: r   z!- runtime flag nonzero observed: r   z (`0x01` samples: r   )z!- mode1 source nonzero observed: r   z)- current object index nonzero observed: r   z- real route/current observed: r   z&- constructed route/current observed: r   z$- source-save load classification: `r   z - source-save ready diversion: `r   z- source-save diversion: `r   z` (r   z:- source-save ready paths route/current/candidate counts: r   z / r   r   z-- source-save diversion current proof count: r   z(- source-save route promotion evidence: r   z- proof found: r'   z%- runtime opcode24 flag proof found: r   z'- failed runtime opcode24 flag gates: `r8   r   z- missing evidence count: r)   z- evidence refs: r   r   z## Missing Evidencez- z## Evidence Refsz| path | fields |z| --- | --- |r*   z| `r   z` | z, r!   r>   z |zd| poll | samples | selectors | route/current | mode1 source | runtime flag | current object | note |z2| --- | ---: | --- | --- | --- | --- | --- | --- |r   r   zconstructed diagnosticr   r    z | `r   r"   /r   rv   z` | `rw   rx   )r   z## Rowsr   zr| poll | row | source ready | samples | selectors | route/current | mode1 source | runtime flag | current object |z8| --- | --- | --- | ---: | --- | --- | --- | --- | --- |rM   rr   rs   z | ro   rt   ru   z` |
)rI   rB   r@   r   rn   rN   extend)summaryr`   rK   linesr   notes         r4   markdownr   z  s   /)/
/ W[[*+6'++h2G1HJ/ gkk*:;<A>	/
  ,= >?qA/ [123/ ,GKK8T,U+VVhipitit  vK  jL  iM  MN  	O/ ,GKK8T,U+VW/ 4GKK@c4d3ef/ *'++6L*M)NO/ 1=Z1[0\]/ /w{{;Y/Z.[[\]/ +7;;7g+h*iijk/ %W[[1R%S$T Ugkk"DEFGq	J/  E;;56
7s;;CD
ES;;GH
I	K!/( 8;;PQ
R	T)/, 3;;BC
D	F-/0 '++l3451/2 0<[0\/]^3/4 2#((7;;Gi;j;pnp2q1rrst5/6 %S5F)G)M2%N$OP7/8 GKK(:;<=9/: 	;/< 	L!'R=/> 	?/@ 	A/B 	C/D #*++.?"@"FB	G$Btf+	GE/F 	G/H 	I/J 	K/L 	M/N 	O/T {{>28b

 #''&/"$tyy1B1Hb'I'PS&QQST

Q/X 	Y/Z 	o[/\ 	=]/E` G$* 
+/884K+L'RVRZRZ[aRb$((8$%T$((=*A)B$yQUQYQYZmQnGoFpptxx89:!DHHE\<];^ _)< =>? @)< =>? @)C DEFd4&PR	T	

 
LL   G$* 	88F#)r 	CLLdhhx()swwv.?tCGGMDZC[[^77=)*$y9M/N.Ot77234Acgg>S6T5U V#CGG,?$@AB C#CGG,?$@AB C#CGG,F$GHIN		 99Ud""Q 
H

s   T"AT'c                F    dt        j                  t        |              dS )Na  <!doctype html><meta charset="utf-8"><title>Runtime Opcode24 Flag Context</title><style>body{font-family:sans-serif;line-height:1.4}table{border-collapse:collapse}td,th{border:1px solid #ccc;padding:4px 6px}code{background:#f3f3f3;padding:1px 3px}</style><pre>z</pre>)htmlescaper   )r   s    r4   	html_pager     s)    	 HW-./v	7r6   c                    |dz  }|j                  t        j                  | dd      dz   d       ||j                  t        |       d       |S )Nz"runtime_opcode24_flag_context.jsonF   )ensure_asciiindentr   r-   r.   )
write_textr1   dumpsr   )r   out_dirhtml_outjson_outs       r4   write_outputsr    s_    
 ==H

7q9D@   Ig.AOr6   c                 ,   t        j                  d      } | j                  dt        t               | j                  dt        d d       | j                         }t               }t        ||j                  |j                        }t        d|        y )	Nz4Summarize runtime opcode24 flag/source observations.)descriptionz	--out-dir)typedefaultz
--html-outz@Optional HTML mirror. Omit to keep the active surface JSON-only.)r	  r
  helpz'wrote runtime opcode24 flag context -> )argparseArgumentParseradd_argumentr   r   
parse_argsr   r  r  r  print)parserargsr   r  s       r4   mainr    s    $$JF $<
O	   DoGWdllDMMBH	3H:
>?r6   __main__)r   r   returndict[str, Any])rA   zlist[Any] | Noner  r:   )rM   list[dict[str, Any]] | Noner  r:   )rM   r  r  r   )rM   r  rY   r:   r  rX   )rd   r  r
   r:   r  list[dict[str, Any]])rK   r  r  z	list[str])rd   r  r  r  )r   r  rd   r  r  r  )r   dict[str, Any] | Noner  r  )NN)r   r  r   r  r  r  )r   r  r  r:   )r   r  r  r   r  zPath | Noner  r   )r  None)$__doc__
__future__r   r   r1   r  pathlibr   typingr   __file__resolveparentsROOTr   r   r   r   r   r   r5   rB   rN   rU   r[   rh   rp   rz   r   r   r   r   r   r  r  __name__r_   r6   r4   <module>r$     sS   N "      H~''*
Ul 3<<'!&  QZZ?!& "R[[>!& )Ybb>!& +MVV4!& +[ddB!& +cll5!%W2
h
) %* & ;M
 aM
 UM
 k
 D
 H
 J
O0' #f8A^he"$2+^ +/>Bd'd&;d dNK#\    
	@" zF r6   