
    Ij                    j   d Z ddlmZ ddl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Zdd	Zdd
ZddZddZdd dZd!dZd"dZd#dZd$dZd%dZ	 d&	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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),zJSummarize grounded event/script VM semantics and remaining execution gaps.    )annotationsN)Path)Any   outc                    	 t        j                  | j                  d            }t	        |t
              r|S i S # t        $ r i cY S w xY w)Nutf-8encoding)jsonloads	read_textFileNotFoundError
isinstancedict)pathdatas     =/home/exedev/hwanse/tools/summarize_event_vm_semantics_gap.py	load_jsonr      sL    zz$..'.:; dD)41r1  	s   %; A	A	c                V    | D cg c]  }|j                  d      dk(  s| c}S c c}w )NhandlerSectionz.textgetrowsrows     r   code_handler_rowsr      s'    HC377+;#<#GCHHHs   &&c                ~    | D ch c]-  }|j                  d      rt        |j                  d            / c}S c c}w )NhandlerVaHex)r   strr   s     r   unique_handlersr!      s>     77>" 	CGGN#$  s   2:c                t    t        | t        t        f      rt        j                  | dd      S t        |       S )NFT)ensure_ascii	sort_keys)r   r   listr   dumpsr    )values    r   
json_valuer(   %   s-    %$&zz%etDDu:    c                $    |t        | xs d      v S )N )r    )textneedles     r   text_containsr.   +   s    S_$$r)   c                    t        j                  | t        |xs d            }|s|S 	 t        |j	                  d            S # t
        $ r |cY S w xY w)Nr+   r   )researchr    intgroup
ValueError)patternr,   defaultmatchs       r   parse_first_intr8   /   sN    IIgs4:2/E5;;q>"" s   A AAc                    t        j                  | t        |xs d            }|sg S |j                  d      j	                  d      D cg c]  }|s|	 c}S c c}w )Nr+   r   ,)r0   r1   r    r3   split)r5   r,   r7   parts       r   parse_opcode_listr=   9   sK    IIgs4:2/E	"[[^11#6?T$D???s   
AAc                X    | xs i } | j                  d      }t        |t              r|S | S )Ndialogue)r   r   r   )payloadr?   s     r   dialogue_candidate_payloadrA   @   s-    mG{{:&H!(D18>w>r)   c                t   t        |       } t        | j                  d      xs d      }t        | j                  d      xs d      }t        | j                  d      xs d      }t        | j                  d      xs d      }t        | j                  d      xs d      }t        | j                  d      xs d      }t        | j                  d      xs d      }t        | j                  d	      xs d      }t        | j                  d
      xs d      }	t        | j                  d      xs d      }
i ddd| j                  d      xs ddt        |d      dt	        d|      dt        d|      dt	        d|      dt	        d|      dt	        d|      d|dt	        d|      dt	        d |      d!t	        d"|      d#t	        d$|      d%t	        d&|      d't        |d(      rd)ndd*t        |d+      rd,ndd-t	        d.|      i d/|d0|d1|d2|d3|d4|d5d6j                  d7 |	|
fD              d8t        |d9      d:t        |d;      d<t        |d=      d>t        |d?      d@t        |dA      dBt        |dC      xr t        |dC      dDt        |dE      dFt        |dG      dHt        |dI      xr t        |dJ      dKt        |dL      xr t        |dM      t        |dN      t        |dO      t        |dP      t        |dQ      t        |dR      t        |	dS      xr t        |
dT      | j                  d      dUk(  xr` t        |d      xrR t        |d;      xrD t        |dA      xr6 t        |dG      xr( t        |dN      xr t        |dQ      xr t        |dR      dVdVdVdW
S )XNdialogueChromer+   dialogueControlFlowdialogueRenderStatedialogueDisplayStyledialogueDisplayStyleProbedialogueCursorRelativeLayoutdialogueLiteralPayloaddialogueObjectFocuspointerDialogueAdvancekeyboardInputWaitLatchsource*out/dialogue_candidate_review_summary.jsonstatusnot-generatedgroundedControlEffectsExecutedzgroundedControlEffects=True!groundedControlExecutedEventCountzgroundedControlEvents=(\d+) groundedControlExecutedOpcodeSetz$groundedControlOpcodes=([0-9a-fx,]+)'groundedControlWaitForInputReleaseCountzgroundedControlWaits=(\d+)groundedControlBranchCallCountzgroundedControlBranches=(\d+)"groundedControlObjectPositionCountzgroundedControlObjects=(\d+)controlFlowSummarybranchExecutionStepCountzbranchExecSteps=(\d+)branchExecutionRenderCountzbranchExecRenders=(\d+)branchExecutionLineAdvanceCountzbranchExecLineAdvances=(\d+)branchExecutionWaitCountzbranchExecWaits=(\d+)branchExecutionReturnCountzbranchExecReturns=(\d+)branchTextOriginz#branchTextOrigin=5:0x0045ee44:16,16z5:0x0045ee44:16,16branchGlobalTimerz branchGlobalTimer=5:0x0045ee4c:0z5:0x0045ee4c:0renderStateSnapshotCountzsnapshots=(\d+)renderStateSummarydisplayStyleSummarydisplayStyleProbeSummarycursorRelativeSummaryliteralPayloadSummaryobjectFocusSummaryinputWaitSummary c              3  &   K   | ]	  }|s|  y wN ).0r<   s     r   	<genexpr>z2browser_dialogue_replay_summary.<locals>.<genexpr>j   s     $tdosT$ts   +browserEventVmControlFlowSummaryImplementedz0browserEventVmControlFlowSummaryImplemented=True(browserEventVmBranchExecutionImplementedz-browserEventVmBranchExecutionImplemented=True)browserEventVmBranchTextOriginImplementedz.browserEventVmBranchTextOriginImplemented=True*browserEventVmBranchGlobalTimerImplementedz/browserEventVmBranchGlobalTimerImplemented=True,browserEventVmRenderStateSnapshotImplementedz1browserEventVmRenderStateSnapshotImplemented=True%browserEventVmDisplayStyleImplementedz*browserEventVmDisplayStyleImplemented=True*browserEventVmDisplayTimerStateImplementedz/browserEventVmDisplayTimerStateImplemented=True+browserEventVmBranchDisplayStyleImplementedz+branchDisplayStyle=12:0x004ec78e:1:emphasis-browserEventVmBranchObjectPositionImplementedz*branchObjectPosition=12:0x004ec79a:144,248zbranchObject=5:0x004e8000:0,352+browserEventVmBranchDisplayTimerImplementedz%branchDisplayTimer=12:0x004ec7a2:2880z$branchDisplayTimer=5:0x004e7ffc:1856z2browserEventVmCursorRelativeLayoutImplemented=Truez2browserEventVmBranchCursorRelativeImplemented=TruezbranchDataBank=4:0x004e8088:0z4browserEventVmLiteralTextPayloadLineImplemented=Truez1browserEventVmObjectPositionFocusImplemented=TruezbranchWaitLatch=Truez-browserDialogueInputWaitLatchImplemented=TruepassedF)
-browserEventVmCursorRelativeLayoutImplemented-browserEventVmBranchCursorRelativeImplemented'browserEventVmBranchDataBankImplemented/browserEventVmLiteralTextPayloadLineImplemented,browserEventVmObjectPositionFocusImplemented(browserDialogueInputWaitLatchImplemented'browserGroundedControlReplayImplemented browserEventVmFullImplementation!originalEventVmRuntimeImplemented#originalStoryFlagRuntimeImplemented)rA   r    r   r.   r8   r=   join)smokedialogue_chromedialogue_control_flowdialogue_render_statedialogue_display_styledialogue_display_style_probedialogue_cursor_relativedialogue_literal_payloaddialogue_object_focuspointer_dialogue_advancekeyboard_input_wait_latchs              r   browser_dialogue_replay_summaryr   F   sb   &u-E%))$45;<O		*? @ FBG		*? @ FBG +A!B!HbI#&uyy1L'M'SQS#T "599-K#L#RPRS"599-E#F#L"M		*? @ FBG"599-E#F#L"M #EII.F$G$M2 Nf>f%))H%8f 	)-If*gf 	,_=[]l-m	f
 	+,=>egv,wf 	2?C`bq3rf 	)/:Z\k*lf 	-o>]_n.of 	3f 	#O4LNc$df 	%o6PRg&hf 	*?;Z\q+rf 	#O4LNc$df 	%o6PRg&hf 	MBWY~40  FHf  	?TVx1y-  @B!f" 	#O4FH]$^#f$ 	3%f& 	5'f( 	#$@)f* 	 !9+f, 	 !9-f. 	3/f0 	CHH$t7OQj6k$tt1f2 	6}!>8
3f: 	3M!;5
;fB 	4]!<6
CfJ 	5m!=7
KfR 	7!?9
SfZ 	002^_ j:<hi_fb 	5m"=7
cfj 	6}(98
kfr 	868de [68YZwfz 	668_` `68^_fB :G$@:
 :G$@:
 4A$+4
 <I$B<
 9F!?9

 24JK j79hi IIh8+ jo/LMj35dej 35hij :<ij	j
 68lmj 68noj 35hi,1-2/4Kf fr)   c                 Z    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gS )NfullInstructionLengthDecodemissingzGDecode the full save-selector/event-object VM instruction length space.zSOnly text-source, cursor, and selected control/display opcode lengths are grounded.)idrO   requiredEvidencecurrentEvidencefullOperandLayoutDecodezSDecode operand layouts and stack/state effects for the full relevant VM opcode set.zaText-source, cursor, and selected control/display effects are grounded; the rest remains partial.routeLinkedEventVmExecutionzaCapture normal map interaction dispatching a story dialogue through the original event/object VM.z^Indexed browser dialogue candidates replay extracted metadata without original route dispatch.sceneEventDialogueBindingzGBind scene event records or runtime dispatch to a story dialogue block.zRScene event text refs are zero and dialogue blocks are storage-indexed candidates.originalStoryFlagMutationzPIdentify and execute original story/event flag mutations for completed dialogue.z=Browser progress flags are prototype-local save/load markers. fullBrowserEventVmImplementationzOExecute the full original event/object VM bytecode path in the browser runtime.zQBrowser replay is limited to known opcode traces for indexed dialogue candidates.eventDrivenBattleEntryz3Prove event VM dispatch into original battle entry.zEDialogue-battle links and battle rows are browser prototype surfaces.rj   rj   r)   r   promotion_gate_rowsr      s     0 it		
 , u  C		
 0 !D		
 . is		
 . r^		
 5 qr		
 + Uf		
K+ +r)   c            
         t               } | D cg c]  }|d   dk7  r|d    }}dddddt        |       t        |      || d	S c c}w )	NrO   rw   r   zout/event_vm_semantics_gap.jsonzAbrowser-partial-known-opcode-replay-not-original-event-vm-runtimezVknown text-source/cursor/control/display opcode replay for indexed dialogue candidatesF)	rM   classificationbrowserReplayScope$browserReplayPromotesOriginalEventVmallRequiredGatesPassedrequiredGateCountmissingGateCountmissingGateIdsrequiredGates)r   len)required_gatesr   missing_gate_idss      r   promotion_gate_summaryr      sq    (*N "x=H$ 	D	  4]d05"' 0 01*' s   Ac                .   | j                  d      xs g }|j                  d      xs i }	|j                  d      xs g }
t        |
      }d| j                  d      xs d| j                  d      | j                  dt        |            | j                  d	d
      | j                  dd
      | j                  d      dddd
}d|	j                  d      |	j                  dt        |
            t        |
      t        |      t        t        |            |	j                  d      |	j                  d      |	j                  d      du |j                  dd
      |j                  dd
      |j                  dd
      |j                  d      xs i d}d|j                  dd
      |j                  d      xs i |j                  dd
      |j                  dd
      |j                  d       du |j                  d!      xs i |j                  d"      xs i d#}|j                  d$      xs i }|j                  d%      xs i }i d&d'd(|j                  d)      xs dd|j                  d*      du d+|j                  d+      du d,|j                  d,      du d-|j                  d-      xs i d.|j                  d.      du d/|j                  d/      xs i d0|j                  d0d
      d1|j                  d1      du d2|j                  d2d
      d3|j                  d3      xs i d4|j                  d4      xs i d5|j                  d5      xs i d6|j                  d6d
      d7|j                  d7d
      d8|j                  d8      xs g |j                  d9d
      |j                  d:      du |j                  d;      du |j                  d<d
      |j                  d=      du |j                  d>      du |j                  d?      du |j                  d@      du |j                  dA      du |j                  dB      du dC
}dD|j                  dEd
      |j                  dFd
      |j                  dGd
      |j                  d      xs i t	        dH |j                  dI      xs g D              t        |j                  dI      xs g D ch c]1  }|j                  dJ      xs i j                  dK      xs g D ]  }| 3 c}}      t	        dL |j                  dI      xs g D              t	        dM |j                  dI      xs g D              t	        dN |j                  dI      xs g D              t	        dO |j                  dI      xs g D              t        |j                  dI      xs g D ch c]1  }|j                  dJ      xs i j                  dP      xs g D ]  }| 3 c}}      dQ}dR|j                  dSd
      |j                  dTd
      |j                  dUd
      |j                  dVd
      |j                  dWd
      dX}t        |      }t               }i dYt        |d         dZt        |d         xr |d   xr |d[   |d   k(  d\|d   d]k\  d^|d   d
kD  d+|d+   d,|d,   d.|d.   d1|d1   d:|d:   d;|d;   d=|d=   d_|dE   d
kD  d`|d(   dak(  db|db   dc|dd   de|df   dg|dh   |di   |dj   |dk   |dl   ddd|dT   d
kD  |dm   d
kD  dddddn}dodpdqdrdsdpdtdrd?dpdudrdvdpdwdrdxdpdydrg}i ddzd&g d{d)d|d}|d~   d|d   d|d   d|d|d|d|d|d|d|d|d%|d|d|d   g dddS c c}}w c c}}w )NentrieseventHandlerTabletableEntriesout/script_handler_table.jsonscoperP   handlerTableVaHexopcodeCountcodeHandlerCountr   defaultHandlerCountdefaultHandlerVaHexTF)
rM   r   r   r   r   r   r   firstByteCandidateOnlyinstructionLengthFullyDecodedoperandLayoutFullyDecoded,out/save_selector_branch_state_dispatch.json
tableVaHex
entryCountdispatcherVaHexdispatchCallVaHexdispatcherVerifiedhandlerCountmatchedHandlerCountdirectTextRoutineHandlerCountclassificationCounts)rM   r   r   tableEntryCounttextEntryCountuniqueCodeHandlerCountr   r   r   handlerScanCountmatchedTextHandlerCountr   r   out/event_text_source_flow.jsoncommandCountcommandCountsByOpcodeopcode0dMediumCommandCountrouteLinkedCommandCountopcode0cAllPointerOverlappointerOverlapCountsByOpcodeconfidenceCounts)rM   r   r   r   r   $routeLinkedCommandsArePointerOverlapr   r   coveragechecksrM   "out/event_vm_opcode_semantics.jsonrO   promotionStatuseventObjectDispatcherVerifiedtextSourceOpcodeLengthsDecoded"textSourceOperandSemanticsGroundeddecodedTextSourceOpcodeLengthsdisplayCursorOpcodeGrounded!decodedDisplayCursorOpcodeLengthsdisplayCursorCommandCountcontrolOpcodeSemanticsGroundedgroundedControlOpcodeCountdecodedControlOpcodeLengthsvariableLengthControlOpcodescontrolOpcodeCommandCountsgroundedControlCommandCountgroundedControlEventCountgroundedControlEventOpcodeSet)groundedControlSampleEffectExecutionCount%browserGroundedControlEventsPreservedliteralStorageOpcodeObservedliteralStorageEventCount!opcode0cPointerOverlapNotPromoted(browserPartialReplayMatchesTextSemanticsr   browserFullEventVmImplemented!fullInstructionLengthFullyDecodedfullOperandLayoutFullyDecoded)
r   r   r   r   r   r   r   r   r   r   out/event_dialogue_blocks.json
blockCountdialogueLikeBlockCountrouteLinkedBlockCountc              3  l   K   | ],  }|j                  d       xs i j                  d      du rd . yw)vmTrace&browserEventVmPartialReplayImplementedTr   Nr   rk   blocks     r   rl   z build_summary.<locals>.<genexpr>_  s;      )
		)$*//0XY]aa )
s   24blocksr   implementedOpcodesc              3  v   K   | ]1  }|j                  d       xs i j                  d      xs ddkD  rd 3 yw)r   literalTextEventCountr   r   Nr   r   s     r   rl   z build_summary.<locals>.<genexpr>i  s@      )
9%+001HINQRSS )
   79c              3  ~   K   | ]5  }t        |j                  d       xs i j                  d      xs d       7 yw)r   r   r   Nr2   r   r   s     r   rl   z build_summary.<locals>.<genexpr>n  s<      )
 9%+001HINQO)
   ;=c              3  v   K   | ]1  }|j                  d       xs i j                  d      xs ddkD  rd 3 yw)r   r   r   r   Nr   r   s     r   rl   z build_summary.<locals>.<genexpr>r  sA      /
9%+001LMRQRVWW /
r   c              3  ~   K   | ]5  }t        |j                  d       xs i j                  d      xs d       7 yw)r   r   r   Nr   r   s     r   rl   z build_summary.<locals>.<genexpr>w  s=      /
 9%+001LMRQRS/
r   groundedControlOpcodeSet)rM   r   r   r   r   partialVmReplayBlockCountpartialVmReplayOpcodeSetliteralVmReplayBlockCountliteralVmReplayEventCountgroundedControlReplayBlockCountgroundedControlReplayEventCountgroundedControlReplayOpcodeSetout/scene_event_text_refs.json
eventCountdirectTextRefCounttextTableRefCounttextCandidateCounttextClusterCount)rM   r  r  r	  r
  r  scriptHandlerTableMappedeventObjectHandlerTableMappedr   opcode0bTextRoutineGroundedr   opcode0dTextSourceGroundeddialogueStorageIndexedbrowserDialogueProgressSmokerw   r~   browserEventVmBranchExecutionrn   !browserEventVmRenderStateSnapshotrq   browserEventVmDisplayStylerr   rx   r{   r|   r}   r   )"browserEventVmCursorRelativeLayout browserEventVmLiteralPayloadLine!browserEventVmObjectPositionFocusbrowserDialogueInputWaitLatchr   r   r   sceneEventDirectTextRefsbrowserEventVmPartialReplayr   browserEventVmImplementationeventVmPromotionGatePassedstoryDialogueRouteProofr   r   a  Text-source event/object opcodes 0x0b/0x0c/0x0d, cursor opcode 0x02, and control/display opcodes 0x03/0x04/0x06/0x07/0x08/0x09/0x0a/0x0e/0x15/0x1b/0x37 now have grounded lengths, variants, or stack effects, but the full save-selector and event/object VM instruction set is not decoded.)r   rO   gapr   zText-source operand effects, opcode 0x02 cursor effects, and several control/display effects are grounded, but many event/object opcodes and the save-selector stream operand layouts remain partial.zkNo normal map interaction has been captured dispatching a story dialogue block through the event/object VM.r  zXCurrent scene event windows have no direct Korean text pointer or text-table references.r  a&  The web runtime now records a partial 0x02/0x0d/0x0b/0x35 replay trace for indexed dialogue candidates and WebKit-smoke-verified bounded branch/control replay for dialogue render/style/cursor/object/input-wait snapshots, but it still does not execute the full original event/object VM bytecode.zQEvent/object VM and save-selector script VM semantic coverage for dialogue proof.)r   r   z out/event_handler_text_refs.jsonr   r   r   r  rN   z*handler-storage-grounded-execution-missingbrowserReplayClassificationr   r   r   saveSelectorScriptHandlerTableeventObjectHandlerTableeventTextSourceFloweventVmOpcodeSemanticsdialogueStorageIndexsceneEventTextRefsbrowserDialogueReplaySmokeeventVmPromotionGate
gapSummary#remainingOriginalEventVmProofInputsr   )zKCapture route-linked event/object VM execution from normal map interaction.zPDecode full instruction lengths and operand layouts for the relevant VM opcodes.zjBind scene event records or runtime dispatch to a story dialogue block instead of storage-only candidates.zYKeep browser partial replay non-promoting until every event VM promotion gate has passed.a  Handler tables, opcode 0x0b text rendering, opcode 0x0d text-source production, and dialogue storage blocks are grounded. The evidence still cannot promote story dialogue execution because only the text-source subset, opcode 0x02 cursor/separator, and a small control/display opcode subset are grounded; route-linked VM execution is absent, scene event text refs are zero, and the browser runtime only records partial dialogue replay plus bounded browser-side branch/control replay for indexed dialogue candidates rather than executing the full original event VM bytecode. The event VM promotion gate classifies that browser replay as non-promoting until route dispatch, full decode, story flag mutation, full browser VM execution, and event-driven battle entry are proven.)nextEvidenceNeeded
conclusion)	r   r   r   r!   sumsortedr   r   bool)script_handler_tablebranch_state_dispatchevent_handler_text_refsevent_text_source_flowevent_vm_opcode_semanticsevent_dialogue_blocksscene_event_text_refs)candidate_dialogue_progress_browser_smokescript_entriesdispatch_tabledispatch_entriesdispatch_code_entriesscript_summaryevent_table_summarytext_flow_summaryopcode_coverageopcode_checksopcode_semantics_summaryr   opcodedialogue_summaryscene_text_summarybrowser_replay_summarypromotion_gater   gap_summarys                             r   build_summaryrG     s
    *--i8>BN*../BCIrN,00@FB-.>?1%))'2Eo1556IJ+//s>?RS0445GK3778MqQ3778MN"&).%*N A$((6$((s;K7LM/034"%o6K&L"M)--.?@+//0CD,001EF$N377J#:#>#>?TVW#X)@)D)DEdfg)h 7 ; ;<R S YWY  4.22>1E!7!;!;<S!T!ZXZ&<&@&@A]_`&a#9#=#=>WYZ#[0F0J0JKf0gko0o(>(B(BCa(b(hfh2667IJPb	 033J?E2O-11(;ArM# 6# +//0ABUo#  	m//0OPTXX#  	)-*;*;<\*]ae*e	# 
 	-m.?.?@d.eim.m#  	)/*=*=>^*_*ece#  	&}'8'89V'W[_'_#  	,_-@-@Ad-e-kik#  	$_%8%89TVW%X#  	)-*;*;<\*]ae*e#  	%o&9&9:VXY&Z#  	&':':;X'Y'_]_#  	'(;(;<Z([(a_a#  	%o&9&9:V&W&][]#  	&':':;XZ['\#   	$_%8%89TVW%X!# " 	()<)<=\)])cac## $ 6E5H5H76

 EF$N(5(9(9:X(Y]a(a$3$7$78RTU$V-:->->?b-cgk-kHITQ'4'8'89V'W[_'_)6):):;Z)[_c)c-:->->?b-cgk-k)6):):;Z)[_c)cE# J 3+//a@"7";";<TVW"X!6!:!:;RTU!V 5 9 9:P Q WUW%( )
.228<B)
 &

 %+.228<B,
!IIi06B;;<PQWUW,
  ,
,
 %
 &) )
.228<B)
 &

 &) )
.228<B)
 &
 ,/ /
.228<B/
 ,

 ,/ /
.228<B/
 ,
 +1.228<B2
!IIi06B;;<VW][]2
  2
2
 +E'R 3+//a@3778LaP2667JAN3778LaP1556H!L ==fg+-N#"D8K)L$M#'$\23 \#$89\#$56:Ml:[[# 	&':;Z'[_`'`# 	%&78T&UXY&Y# 	)*BCc*d# 	-.FGk.l# 	&'?@]'^# 	)*BCc*d# 	01IJq1r# 	'(@A_(`# 	,-EFi-j#  	!"2<"@1"D!#" 	'(>x(HH(T##$ 	23IJs3t%#& 	()?@j)k'#( 	,-CDr-s)#* 	%&<=d&e+#, /EEt.u,BCt,u-CDr-s)?@j)k).%*',$67K$Lq$P'78S'TWX'X05(-&+#(E#FL 2T			
 .{		
 0 A	
 -m	
 1y		
;&KN+d+ 	
+ 	G+ 	&~6F'G+ 	n-AB+ 	/?e0f+  	).!+" 	"#6#+$ 	0%+& 	!":'+( 	 0)+* 	0++, 	%&<-+. 	/+0 	&1+2 	k3+4 	.~>N/O5+6
pE+ +e,
.2
s   6^66^ c                   d| d   fd| d   fd| d   fd| d   fd	| d
   fd| d   fd| d   fd| d   fd| d   fg	}dd| d   dd| d    dd| d    dd| d    ddt        | d          ddg	}|D ]g  \  }}|j                  d| dd d!g       |j                         D ]&  \  }}|j                  d"| d#t        |       d$       ( |j                  d       i |j                  g d%       | d&   D ]&  }|j                  d"|d'    d(|d)    d*|d+    d$       ( |j                  g d,       |j                  d- | d.   D               d/j	                  |      d/z   S )0N"Save-Selector Script Handler Tabler   Event/Object Handler Tabler!  Event Text Source Flowr"  Event VM Opcode Semanticsr#  Dialogue Storage Indexr$  Scene Event Text Refsr%  Browser Dialogue Replay Smoker&  Event VM Promotion Gater'  Checksr   z# Event VM Semantics Gapr+   r+  z- promotion status: `r   `z - browserReplayClassification: `r  z)- browserReplayPromotesOriginalEventVm: `r   z(- remainingOriginalEventVmProofInputs: `r)  z## z| field | value |z| --- | --- |z| z | z |)z## Gapsr+   z| id | status | gap |z| --- | --- | --- |r(  r   z | `rO   z` | r  )r+   z## Next Evidence Neededr+   c              3  &   K   | ]	  }d |   yw)z- Nrj   rk   items     r   rl   zmarkdown.<locals>.<genexpr>2  s     G2dVGs   r*  
)r(   extenditemsappendr   )summarysectionslinestitler   keyr'   r   s           r   markdownr_    s   	-w7W/XY	%w/H'IJ	!7+@#AB	$g.F&GH	!7+A#BC	 '*>"?@	('2N*OP	"G,B$CD	78$%
H 	#


(9 :;1=
*73P+Q*RRST
3G<b4c3ddef
2:gFk>l3m2nnop

E   	t%M	
 	 **, 	=JCLL2cU#j&7%8;<	=R	 
LL   |$ Lr#d)DXtCJ<rJKL	LL  
 
LLG1E)FGG99Ud""r)   c                N    dj                  d | j                         D              S )NrV  c           	   3     K   | ]?  \  }}d t        j                  |       dt        j                  t        |             d A yw)<tr><td>z	</td><td>
</td></tr>N)htmlescaper(   )rk   r^  r'   s      r   rl   zhtml_table.<locals>.<genexpr>7  sD      C 4;;s#$Idkk*U:K.L-MZXs   AA)r   rX  )r   s    r   
html_tablerf  6  s&    99 **,  r)   c                   d| d   fd| d   fd| d   fd| d   fd	| d
   fd| d   fd| d   fd| d   fd| d   fg	}g }|D ]<  \  }}|j                  dt        j                  |       ddt        |       dg       > dj	                  d | d   D              }dj	                  d | d   D              }dj	                  ddddd d!d"d#d$d%t        j                  | d&          d'd(t        j                  | d)          d*d+t        j                  | d,          d*d-t        j                  t        | d.                d*d/t        j                  t        | d0                d*g|d1d2| dd3d4| d5d6d7d8      S )9NrI  r   rJ  r!  rK  r"  rL  r#  rM  r$  rN  r%  rO  r&  rP  r'  rQ  r   z  <h2>z</h2>zD  <table><thead><tr><th>field</th><th>value</th></tr></thead><tbody>z</tbody></table>rV  c           
   3     K   | ]R  }d t        j                  |d          dt        j                  |d          dt        j                  |d          d T yw)rb  r   z</td><td><code>rO   z</code></td><td>r  rc  Nrd  re  )rk   r   s     r   rl   zhtml_page.<locals>.<genexpr>R  sg       	{{3t9%& '[[X/0 1{{3u:&' (	s   AAr(  c              3  N   K   | ]  }d t        j                  |       d  yw)z<li>z</li>Nri  rT  s     r   rl   zhtml_page.<locals>.<genexpr>Z  s#     etT$++d"3!4E:es   #%r*  z<!doctype html>z<html lang="en">z<head>z  <meta charset="utf-8">z'  <title>Event VM Semantics Gap</title>a    <style>body{font-family:system-ui,sans-serif;margin:24px;line-height:1.45;max-width:1200px}table{border-collapse:collapse;width:100%;margin:16px 0}td,th{border:1px solid #ddd;padding:6px 8px;text-align:left;vertical-align:top}th{background:#f5f5f5}code{white-space:nowrap}</style>z</head>z<body>z!  <h1>Event VM Semantics Gap</h1>z  <p>r+  z</p>z$  <p><b>Promotion status:</b> <code>r   z</code></p>z/  <p><b>browserReplayClassification:</b> <code>r  z8  <p><b>browserReplayPromotesOriginalEventVm:</b> <code>r   z7  <p><b>remainingOriginalEventVmProofInputs:</b> <code>r)  z  <h2>Gaps</h2>zN  <table><thead><tr><th>id</th><th>status</th><th>gap</th></tr></thead><tbody>z  <h2>Next Evidence Needed</h2>z  <ul>z</ul>z</body>z</html>r+   )rW  rd  re  rf  r   r(   )rZ  r[  section_htmlr]  r   gap_rows
next_itemss          r   	html_pagern  =  se   	-w7W/XY	%w/H'IJ	!7+@#AB	$g.F&GH	!7+A#BC	 '*>"?@	('2N*OP	"G,B$CD	78$%
H L tT[['(.$T*++;=
 	 yy  <( H ewOcGdeeJ99"1 	e+
GL12348
.t{{7CT;U/V.WWbc[[)F!GHIV[[G4Z,[!\]^^ik[[G4Y,Z![\]]hj+ 0 
1 2 	3 4 YYaXbbrs5 6 	*7 8 E"9 : 	; < 	= > 	?     r)   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okzevent_vm_semantics_gap.jsonF   )r#   indentrV  r	   r
   event_vm_semantics_gap.html)mkdir
write_textr   r&   rn  )rZ  out_dirs     r   write_outputsrx  ~  sd    MM$M.,,88

7q9D@ 9  ,,8879KV]8^r)   c                 v   t        j                  t              } | j                  dt        t
               | j                         }t        t        |j                  dz        t        |j                  dz        t        |j                  dz        t        |j                  dz        t        |j                  dz        t        |j                  d	z        t        |j                  d
z        t        |j                  dz              }t        ||j                         t        d|j                  dz          y )N)descriptionz	--out-dir)typer6   zscript_handler_table.jsonz(save_selector_branch_state_dispatch.jsonzevent_handler_text_refs.jsonzevent_text_source_flow.jsonzevent_vm_opcode_semantics.jsonzevent_dialogue_blocks.jsonzscene_event_text_refs.jsonz&dialogue_candidate_review_summary.jsonz wrote event VM semantics gap -> rt  )argparseArgumentParser__doc__add_argumentr   OUT
parse_argsrG  r   rw  rx  print)parserargsrZ  s      r   mainr    s    $$9F
$<D$,,!<<=$,,!KKL$,,!??@$,,!>>?$,,!AAB$,,!==>$,,!==>$,,!IIJ	G '4<<(	,T\\<Y-Y,Z
[\r)   __main__)r   r   returnr   )r   
list[dict]r  r  )r   r  r  zset[str])r'   r   r  r    )r,   r    r-   r    r  r.  )r   )r5   r    r,   r    r6   r2   r  r2   )r5   r    r,   r    r  z	list[str])r@   dict | Noner  r   )r   r  r  r   )r  r  )r  r   ri   )r/  r   r0  r   r1  r   r2  r   r3  r   r4  r   r5  r   r6  r  r  r   )rZ  r   r  r    )r   r   r  r    )rZ  r   rw  r   r  None)r  r  )"r~  
__future__r   r|  rd  r   r0   pathlibr   typingr   __file__resolverp  ROOTr  r   r   r!   r(   r.   r8   r=   rA   r   r   r   rG  r_  rf  rn  rx  r  __name__rj   r)   r   <module>r     s#   P "    	   H~''*
Ul2I%@?rj,^< >BAAA "A !	A
  $A  A  A 0;A 
AH/#d>B 25 _]$ zF r)   