
    _j5                         d dl Z d dlZd dlZd dlZd dlmZ  ee                                          j        d         Z	dZ
dZg dZg dZd Zd	 Zd
 Zd Zd Zd Zedk    r e             dS dS )    N)Path   zrun-002v4)		candidateoutlinestory_brief
charactersledgeridentity_registryreveal_ledgercandidate_validationoriginality_receipt)r   r	   r   r
   r   r   c                    t          j                    }|                     d          5 t          fdd          D ]}|                    |           	 d d d            n# 1 swxY w Y   |                                S )Nrbc                  .                          d          S )Ni   )read)handles   script/promote-story.py<lambda>zsha256.<locals>.<lambda>#   s    &++o">">     r   )hashlibsha256openiterupdate	hexdigest)pathdigestblockr   s      @r   r   r       s    ^F	4 !F>>>>DD 	! 	!EMM%    	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! s   ,A##A'*A'c                     t          j        d | D             ddd                              d          }t          j        |                                          S )Nc                 ,    i | ]}|d          |d         S r   r    .0rows     r   
<dictcomp>z$audit_set_digest.<locals>.<dictcomp>*   s"    444Vc(m444r   FT),:)ensure_ascii	sort_keys
separatorsutf-8)jsondumpsencoder   r   r   )rowspayloads     r   audit_set_digestr3   (   s`    j44t444	  
 fWoo  >'"",,...r   c                    | j                             dd           |                     | j        dz             }t	          |d          5 }|                    |           |                                 t          j        |	                                           d d d            n# 1 swxY w Y   t          j
        ||            d S )NT)parentsexist_ok.partxb)parentmkdirwith_suffixsuffixr   writeflushosfsyncfilenoreplace)r   datapartr   s       r   atomic_bytesrE   2   s    KdT222DK'122D	dD		 "VT
!!!" " " " " " " " " " " " " " " JtTs   
AB&&B*-B*c                 |    t          | t          j        |dd          dz                       d                     d S )NF   )r*   indent
r-   )rE   r.   r/   r0   )r   values     r   atomic_jsonrK   <   s=    
5uQGGG$NVVW^__`````r   c                      t          |           )N)RuntimeError)messages    r   failrO   @   s    
w

r   c                    - t           dz  } t           dz  }t          j        |                     d                    }t          j        |                    d                    }|                    d          t
          k    s|                    d          t          k    rt          d           |                    d          t
          k    s|                    d          t          k    rt          d	           |                    d
          dk    rt          d           |d         -t           -d         z  }t           -d         z  }t           -d         z  }t           -d         z  }t           -d         z  }t           -d         z  }	t           -d         z  }
t           -d         z  }t           -d         z  }t           -d         z  }|
|||fD ]W}|                                s/|	                    |j
        dz                                             rt          d|            X||||||	fD ](}|                                st          d|            )t          |          }t          j        |                    d                    }|                    d
          dk    s|                    d          durt          d           |                    d          t
          k    s|                    d          t          k    rt          d            |                    d!g           }|                    d"          d#k    st          |          d#k    rt          d$           d% |D             t          k    rt          d&           -fd't          D             }d( |D             |k    rt          d)           g }|D ]}t           |d*         z  }|                                st          d+|d*                     |                    |d,         |d*         |                                j        |                                j        t          |          d-           ||k    rt          d.           t%          |          }||                    d/          k    rt          d0           t          |          }|                    d1          |k    rt          d2           t          j        |                    d                    }t          j        |                    d                    }t          j        |                    d                    }t          j        |	                    d                    }d3|fd4|fd5|ffD ]r\  }}|                    d
          d6k    s|                    d          durt          | d7           |                    d1          |k    rt          | d8           s|                    d          t          k    s|                    d          t          k    rt          d9           |                    d:          -d         k    rt          d;           |                    d<          durt          d=           |                    d>          d?k    s|                    d@          d6k    rt          dA           |                    d
          d6k    s|                    d          durt          dB           |                    d          t
          k    s|                    d          t          k    rt          dC           |                    d1          |k    rt          dD           |                    d/          |k    rt          dE           |                    dF          |k    rt          dG           |                    dH          dIus|                    dJ          d6k    rt          dK           |                    dL          d6k    s2|                    dM          dNk    s|                    dO          dNk    rt          dP           |                    dQ          dRk    s|                    dS          dIurt          dT           |                    dUg           }t          |          dRk    st'          dV |D                       rt          dW           t          dX |D                       dRk    rt          dY           dZ |D             } |                    d[          | k    rt          d\           t          |                    d                                                    }!|                    d]          |!k    rt          d^           |                    d_g           }"t          |"          dRk    s+|"dN         |!cxk    r|"d`         k    rn nda|!cxk    rdbk    sn t          dc           |                                }#t-          |
|#           |                    ddi                               deg           }$t          |$          dfk    rt          dg           g }%|$D ]}t           |d*         z  }|                                }&t/          j        |&                                          |dh         k    rt          di|d*                     |&                    dj          r|&                    dk          rt          dl|d*                     |%                    |&           dm                    |%          }'t-          ||'           t          |
          |k    rt          dn           t          |          }(t6          j                            t6          j        j                                                  })d6dt
          t          -d         |(|dodpdqdf|$dd|)dr}*tA          ||*           -fdstB          D             }+i d
dtdddu|du         dt
          dt          dv-d         dw|dx-d         dy|dz-d         d{|(d|-d}         d~d ddd|!dtE          |!dz  df          d/||dddddddd-d         t          |          d-d         t          |          d-d         t          |          d-d         |d-d         t          |	          d-d         t          |          dd|+|)d},tA          ||,           |#                    ddt
          t          |-d         |-d         |(-d}         d |!tE          |!dz  df          |)d           tA          ||           d|d
<   ||d1<   t          |#          |d<   |!|d]<   ||d<   |(|d{<   d |d~<   dt|d         d<   d|d         d<   dtd-d         ||!|)d|d<   |)|d<   tA          | |           tI          t          j%        d||!ddI                     d S )Nzscript/project-manifest.jsonzscript/story-manifest.jsonr-   )encodingrun_idactive_versionz3story manifest run/revision is not promotion target
active_runz,project run/revision is not promotion targetstatuspromotion_readyzproject is not promotion-readyactive_pathsr   r   r   audit_set_locksemantic_reviewproducer_closestory_canonspoken_narration_sourcetts_semantic_assembly_receiptpromotion_receiptr7   z!promotion output must be virgin: z promotion prerequisite missing: FROZENverifiedTz%audit-set lock is not terminal FROZENrevisionz!audit-set lock run/revision driftlocked_fileslocked_file_count	   z.audit-set lock must contain exactly nine filesc                 8    g | ]}|                     d           S )keygetr$   s     r   
<listcomp>zmain.<locals>.<listcomp>l   s"    ...3...r   z#audit-set key order/inventory driftc                 "    i | ]}||         S r#   r#   r%   rf   actives     r   r'   zmain.<locals>.<dictcomp>n   s    >>>3c6#;>>>r   c                 `    i | ]+}|                     d           |                     d          ,S )rf   r   rg   r$   s     r   r'   zmain.<locals>.<dictcomp>o   s.    ???C???r   z*audit-set paths differ from active routingr   zfrozen file missing: rf   )rf   r   bytesmtime_nsr   zfrozen file fingerprint driftaudit_set_sha256z#audit_set_sha256 does not reproducecandidate_sha256zlock candidate hash drift
validationoriginalityzproducer-closePASSz not terminal PASSz candidate hash driftz,validation/producer candidate revision driftcandidate_pathz originality candidate path driftmanual_full_read_verifiedz%producer-close lacks manual full readcorpus_project_count   semantic_architecture_verdictz0originality gate not terminal across 17 projectsz'semantic aggregate is not terminal PASSz%semantic aggregate run/revision driftz"semantic aggregate candidate driftz"semantic aggregate audit-set driftaudit_lock_receipt_sha256z%semantic aggregate lock-receipt driftstaleFprovenance_verdictz0semantic aggregate currentness/provenance failedsemantic_verdictblocker_countr   
high_countz4semantic aggregate did not return 0 BLOCKER / 0 HIGHindependent_auditor_countrG   auditor_disagreementz&two-auditor terminal agreement missingauditor_reportsc              3   D   K   | ]}|                     d           duV  dS )terminalTNrg   r$   s     r   	<genexpr>zmain.<locals>.<genexpr>   s3      SSC
 3 34 ?SSSSSSr   z,two terminal auditor source reports requiredc                 8    h | ]}|                     d           S )report_sha256rg   r$   s     r   	<setcomp>zmain.<locals>.<setcomp>   s$    888CGGO$$888r   z0auditor reports are not independently identifiedc                 ,    i | ]}|d          |d         S r"   r#   r$   s     r   r'   zmain.<locals>.<dictcomp>   s"    IIIcs6{CMIIIr   observed_hashesz6semantic observed hashes do not equal exact frozen setcandidate_wordsz(candidate word count is not reproducibletarget_wordsr   i$  i$6  z0candidate outside locked/40-60-minute word rangeassemblyparts   z6TTS semantic assembly requires exact four source partsr   zTTS source part drift:    
s   

z$TTS source part LF contract failed: s   


z$canon/candidate byte equality failedzZTTS semantic source is distinct from candidate aggregate and has its own separator receiptz.exactly three blank lines between source parts0a0a0a)rU   r`   rR   ra   semantic_source_pathsemantic_source_sha256source_candidate_sha256representation_contractseparator_contract'separator_bytes_added_between_parts_hexboundary_total_consecutive_lfsource_partssource_part_hashes_verifiedsemantic_content_preserved
created_atc                 L    i | ] }|t          t          |         z            !S r#   )r   ROOTrk   s     r   r'   zmain.<locals>.<dictcomp>   s,    KKKSfTF3K/00KKKr   	completed
project_idsource_candidate_pathr   source_canon_pathsource_canon_sha256spoken_narration_source_pathspoken_narration_source_sha256spoken_narration_pathspoken_narrationspoken_narration_sha256pronunciation_statuspending
word_countpredicted_duration_minutes   )r   rY   originality_17_projectsrX   producer_full_readcanon_candidate_byte_equality-tts_semantic_source_three_blank_line_assemblyr"   )r   rY   rs   rX   rZ   tts_semantic_assembly)rz   gatesreceiptsauthority_snapshotcompleted_atpromoted)rU   r`   rR   ra   rq   story_canon_pathstory_canon_sha256r   r   r   r   r   %predicted_duration_minutes_at_231_wpmpromoted_at$story_promoted_pronunciation_pendingcandidate_bytescanon_sha256stepsstorypronunciation)rU   r`   r^   r   r   r   
updated_at)rU   r   r   )r*   )&r   r.   loads	read_textrh   RUN_IDREVISIONrO   existsr;   r<   r   lenFREEZE_KEYSappendstatst_sizest_mtime_nsr3   anysplit
read_bytesrE   r   r   endswithjoindatetimenowtimezoneutc	isoformatrK   AUTHORITY_KEYSroundr   printr/   ).manifest_pathstory_manifest_pathmanifeststory_manifestru   validation_pathoriginality_path	lock_pathsemantic_pathproducer_path
canon_pathsource_pathtts_assembly_pathpromotion_pathoutputprerequisitelock_bytes_hashlocklocked_rowsexpected_pathscurrent_rowsr&   r   current_audit_setcandidate_sharr   rs   semanticproducernamereceiptreportsexpected_hashesr   targetr   	part_rows
part_bytesrawtts_source_bytestts_source_shar   tts_assembly	authority	promotionrl   s.                                                @r   mainr   D   s   99M!==z-1171CCDDHZ 3 = =w = O OPPN(##v--1C1CDT1U1UYa1a1aBCCC||L!!V++x||<L/M/MQY/Y/Y;<<<||H!222-...n%FF;//NV$:;;Of%:;;v.//I6"344M6"233M}--J 9::Kv&EFFF#677N{,=~N ? ?==?? 	?f001HIIPPRR 	?=V==>>>':JIWdfst D D""$$ 	DBLBBCCCY''O:i))7);;<<DxxX%%*)=)=T)I)I4555xxV##txx
';';x'G'G0111((>2..Kxx#$$))S-=-=-B-B=>>>..+...+==2333>>>>+>>>N??;???>QQ9:::L 
 
c&k!{{}} 	86V66777u:KYY[[(		/Tll
 
 	 	 	 	 {"",---(66DHH%788882333>**Mxx"##}44()))O55w5GGHHJ*-777IIJJKz-1171CCDDHz-1171CCDDH'4}k6RUegoTpq 1 1g;;x  F**gkk*.E.ET.Q.QD,,,---;;)**m;;D///000~~j!!X--j1I1IX1U1U;<<<'((F;,???/000||/00<<4555-.."44Hg8h8hlr8r8r?@@@||H''8<<
+C+C4+O+O6777||H''8<<
+C+Cx+O+O4555||&''=881222||&''+<<<1222||/00OCC4555||GE))X\\:N-O-OSY-Y-Y?@@@||&''611X\\/5R5RVW5W5W[c[g[ght[u[uyz[z[zCDDD||/00A55F\9]9]ej9j9j5666ll,b11G
7||qCSS7SSSSS;<<<
8888899Q>>?@@@II[IIIO||%&&/99EFFF^--w-??EEGGHHJ~~'((J667888^^NB//F
6{{avayJCCCC&)CCCCC4S]KfKfKfKfafKfKfKfKf?@@@$//11O_---z2..227B??I
9~~EFFFJ  c&k!oo>#((**c(m;;83v;88999||E"" 	Gcll7&;&; 	GEFEEFFF# ~~j11.///j]**3444K((N



 1 5
6
6
@
@
B
BC &'@ A"0#0#N3;)*!'+&* L" !<000KKKKNKKKI&+&D& 	h|,& 	&	&
 	H& 	 !4& 	"=& 	VM2& 	}& 	'/H(I& 	).& 	 (:!;& 	"4& 		& 	j&  	%eJ,<a&@&@!&" 	-#&$ &5$(#'+""&-1=A
 
 .44J-KW]^mWnWn$o$o(./@(AVTaMbMbcc$*+@$AVTdMeMeff'-.>'??[['-.>'?6R_K`K`aa.45T.Uaghyazaz%{%{
 
 (K& & &IN 	***)"=1+(./H(I*8!'(:!;#' 16zC7G1K1K      #^444?HX#0H "%o"6"6H",H,H^1?H-.*.H&'!,HWg)2HWo&#$78%  HW !H\x(((	$*
MYcddsx
y
y
yzzzzzr   __main__)r   r   r.   r?   pathlibr   __file__resolver5   r   r   r   r   r   r   r3   rE   rK   rO   r   __name__r#   r   r   <module>r     s      				      tH~~'*	
 
 
    / / /  a a a     k{ k{ k{\ zDFFFFF r   