
    _j                         d dl Z d dlZd dlmZ  ee                                          j        d         Zedz  Zedz  Z	g dZ
h dZd Zd	 Zd
 Zd Zedk    r e             dS dS )    N)Path   zwork/story/run-002zscript/project-manifest.json)story_brief
charactersledgeroutlineidentity_registryreveal_ledger>   	frozen_atdraft_progresscandidate_bytescandidate_wordsdraft_aggregatefull_read_linescandidate_sha256frozen_candidate_sha256c                 r    t          j        |                                                                           S N)hashlibsha256
read_bytes	hexdigest)paths    #script/validate-run002-authority.pyr   r      s(    >$//++,,66888    c                      t          |           r   )RuntimeError)messages    r   failr   !   s    
w

r   c              #      K   t          | t                    r5|                                 D ]\  }}|V  t          |          E d {V  d S t          | t                    r| D ]}t          |          E d {V  d S d S r   )
isinstancedictitems	walk_keyslist)valuekeyitems      r   r$   r$   %   s      % ' 	' 	'ICIII &&&&&&&&	' 	' 
E4	 	  ' 	' 	'D &&&&&&&&' '	' 	'r   c                  N   t          j        t                              d                    } |                     d          dk    s|                     d          dk    rt          d           t          dz  }t          d	z  }|                                r|                                st          d
           t          j        |                    d                    }t          j        |                    d                    }|                    d          dk    s|                    d          durt          d           |                    d          t          |          k    rt          d           |                    d          |                    d          k    rt          d           t          fd|                    dg           D             d           }||                    d          durt          d           |                     di           }|                     d          }|dk    rt          d           i }i }	t          D ]h}
t          ||
         z  }|                                st          d|
            |||
<   t          j        |                    d                    |	|
<   i|	d         }|	d         }|	d         }|	d         }|	d          }|	d!         }|	                                D ]\  }
}|                    d"          dk    s|                    d          d#k    rt          d$|
            |                    d          |k    rt          d%|
            |                    d          k    rt          d&|
            |                    d'          t          |          k    rt          d(|
            |                    d)          d*k    s|                    d+          d,k    rt          d-           |                    d.          durt          d/           |                    d0          |                    d1          k    rt          d2           |                    d3          |                    d3          k    rt          d4           |                    d5          |                    d5          k    rt          d6           |                    d7g           }t          |          d8k    s*|d9         d:k     s|d;         d<k    s|d9         |d;         k    rt          d=           |                    d>          d?k    rt          d@           dA |                    dg           D             }t          |          t          t          |                    k    st          dB |D                       rt          dC           |d d8         |                    d3          k    rt          dD           |                    dE          |                    d3d g          d9         k    rt          dF           |                    d5          |                    dE          k    rt          dG           t          t!          |                    }t#          t$          |z            }|rt          dH|            |                    dI          r*|                    dJ          r|                    dK          st          dL           |                    dM          st          dN           |                    dOg           }dP |D             }t          |          dQk     s1|t'          t)          d;t          |          d;z                       k    rt          dR           |                    dSi                               dT          st          dU           t          |                    dVi                     dWk     rt          dX           t          |                    dYg                     d8k     rt          dZ           |                    d[g           }|st          d\           |D ]>}h d]}|t          |          k    s%t          d^|                    d_                      ?d` |                                D             }t          t          |                                                    t          |          k    rt          da           t-          t          j        ddd|t          |          |db |                                D             ddc	dde                     d S )fNzutf-8)encoding
active_runzrun-002statusz&run-002_authority_ready_for_validationz+run-002 authority validation is not enabledzcreative-options.jsonz creative-options-validation.jsonz7Creative Options or terminal validation receipt missingPASSverifiedTz0Creative Options validation is not terminal PASSoptions_sha256z#Creative Options receipt hash driftselected_option_idz selected option receipt mismatchc              3   N   K   | ]}|                     d           k    |V   dS )	option_idNget).0r(   selected_ids     r   	<genexpr>zmain.<locals>.<genexpr>A   s:      iidDHH[DYDY]hDhDhTDhDhDhDhiir   optionseligiblez'selected option is absent or ineligibleactive_pathsauthority_revisionv2z%manifest authority revision is not v2zauthority file missing: r   r   r   r   r	   r
   run_idlocked_pre_prosezauthority status/run mismatch: zauthority revision mismatch: z"selected option binding mismatch: creative_options_sha256z(Creative Options hash binding mismatch: story_family_primaryu   Cưới trước yêu saustory_family_secondaryu
   không cózBrief family lock driftfamily_selected_before_premisezBrief family-first flag missingcanonical_titleworking_titlez(Brief title differs from selected optioncentral_namesz/Brief central names differ from selected optionpovz&Brief POV differs from selected optiontarget_words   r   i$  r   i$6  z;Brief word target violates 40-60 minute contract at 231 wpmtts_words_per_minute   zBrief TTS rate must be 231 wpmc                 8    g | ]}|                     d           S )namer3   r5   r(   s     r   
<listcomp>zmain.<locals>.<listcomp>s   s$    KKK$TXXfKKKr   c              3      K   | ]}| V  d S r    )r5   rL   s     r   r7   zmain.<locals>.<genexpr>t   s$      +G+GH+G+G+G+G+G+Gr   z%character names missing or duplicatedz#central character order/names drift	pov_ownerzPOV owner driftzidentity registry POV driftz7mutable production state leaked into authority Ledger: timeline	knowledgerelationshipz.Ledger timeline/knowledge/relationship missingcontinuity_invariantsz$Ledger continuity invariants missingbeatsc                 8    g | ]}|                     d           S )beatr3   rM   s     r   rN   zmain.<locals>.<listcomp>   s$    333T  333r      z1Outline must contain at least 20 sequential beatsteaser_contractsame_event_catchup_requiredz teaser/catch-up contract missingretention_map   zretention map incompleteclimax_contributionz"climax contribution map incompleterevealszReveal Ledger empty>   id	seed_beat
provenancepartial_beatcannot_supportfull_reveal_beatzReveal Ledger row incomplete: r`   c                 4    i | ]\  }}|t          |          S rP   )r   r5   r'   r   s      r   
<dictcomp>zmain.<locals>.<dictcomp>   s$    IIIICc6$<<IIIr   z+authority files unexpectedly byte-identicalc                 d    i | ]-\  }}|t          |                    t                              .S rP   )strrelative_toROOTrg   s      r   rh   zmain.<locals>.<dictcomp>   s4    fffdCT%5%5d%;%;!<!<fffr   )	r,   r.   r=   r;   r0   r?   authority_hashesauthority_filesprose_write_allowedF)ensure_ascii)jsonloadsMANIFEST	read_textr4   r   RUNexistsr   nextAUTHORITY_KEYSrl   r#   lensetanyr$   sortedFORBIDDEN_LEDGER_KEYSr%   rangevaluesprintdumps)manifestoptions_pathoptions_receipt_pathr8   options_receiptselectedactiver;   authority_pathsauthority_docsr'   r   briefr   r   r   identityr_   docrG   namesledger_keysleakedrV   beat_idsreveal_rowsrowrequiredhashesr6   s                                @r   mainr   /   s	   z(,,g,>>??H||L!!Y..(,,x2H2HLt2t2t:;;;00L!CC   H(<(C(C(E(E HFGGGj///AABBGj!5!?!?!?!Q!QRRO8$$../2E2Ej2Q2QY]2]2]?@@@+,,|0D0DDD2333++233K/00K??/000iiiigkk)R&@&@iiikoppH8<<
334??6777\\."--F!&:;;T!!4555ON K KfSk!{{}} 	31C11222#"j)I)IJJs=)E-JH%FY'G12H_-G"((** C CS778	))SWWX->->BT-T-T838899977'((,>>>66677777'((K77;c;;<<<77,--1E1EEEACAABBByy'((,GGG599UmKnKnr~K~K~&'''yy122$>>.///yy"##x||O'D'DDD7888yy!!X\\/%B%BBB>???yy8<<....566699^R00L
<Aa4!7!7<?U;R;RVbcdVehtuvhwVwVwJKKKyy'((C//-...KK*..r*J*JKKKE
5zzSU__$$+G+G+G+G+G(G(G$4555RaRyHLL11112333~~k""hll?TF&K&KA&NNN||Ejnn[9999*+++i''((K)K788F QOvOOPPP::j!! ?K)@)@ ?

SaHbHb ?=>>>::-.. 53444KK$$E33U333H
5zzB(d5CJJN+C+C&D&DDD@AAA;;("--112OPP 1/000
7;;++,,q00'(((
7;;,b1122Q661222++i,,K $"### C Cjjj3s88##A#''$--AABBBII1F1F1H1HIIIF
3v}}  CKK//:;;;	$*0)#),#7#7"ffoNcNcNeNefff#
 
 
 
 
 
 
 
 
 
r   __main__)r   rq   pathlibr   __file__resolveparentsrl   ru   rs   rx   r}   r   r   r$   r   __name__rP   r   r   <module>r      s           tH~~'*
!!00  	 	 	 9 9 9     ' ' 'w w wt zDFFFFF r   