
    [}\j                       d dl mZ d dlZd dlZd dlZ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edz  Z e
d          Zg dZdd	d
dZd&dZd'dZd(dZd)dZd*dZedk    r	  ej         e                       dS # e$ rZdd ee          j         de ej                            ej        j                                                   d Z!	  ej"        e#                    d!"                    Z$ e ee$d#          e!           n# e$ r Y nw xY w e% ej&        e!d$          ej'        %            ej        d           Y dZ[dS dZ[ww xY wdS )+    )annotationsN)Path   zscript/project-manifest.jsonzN/home/hermes/.hermes/skills/content-creation/tao-anh/scripts/generate_image.py)story_briefidentity_registryreveal_ledgeroutlineright_panel_masterleft_panel_masterintro_masterright_panel
left_panelintropathr   returnstrc                   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/run-artwork.py<lambda>zsha256.<locals>.<lambda>   s    &++o">">     r   )hashlibsha256openiterupdate	hexdigest)r   digestchunkr   s      @r   r   r      s    ^F	4 !F>>>>DD 	! 	!EMM%    	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! s   ,A##A'*A'manifestdictkeyc                   |                      d          pi                      |          }t          |t                    r|st          d| d          t	          |          }|                                s
t          |z  }	 |                                                    t                                                     n%# t          $ r}t          d|           |d }~ww xY w|S )Nactive_pathszactive_paths.z is missingzactive path escapes project: )
get
isinstancer   RuntimeErrorr   is_absoluteROOTresolverelative_to
ValueError)r$   r&   valuer   excs        r   resolve_activer3       s    \\.))/R44S99EeS!! = =;3;;;<<<;;D d{K""4<<>>2222 K K K@3@@AAsJKKs   >C 
C$CC$r1   Nonec                   | j                             dd           t          j        |dd          dz                       d          }t          j        d| j         d| j         	          \  }}	 t          j	        |d
          5 }|
                    |           |                                 t          j        |                                           d d d            n# 1 swxY w Y   t          j        ||            t          j                            |          rt          j        |           d S d S # t          j                            |          rt          j        |           w w xY w)NTparentsexist_okF   )ensure_asciiindent
utf-8.)prefixdirwb)parentmkdirjsondumpsencodetempfilemkstempnameosfdopenwriteflushfsyncfilenoreplacer   existsunlink)r   r1   datafdrI   r   s         r   atomic_jsonrU   .   s   KdT222Ju5;;;dBJJ7SSD'749'7'7'7T[IIIHBYr4   	&FLLLLNNNHV]]__%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	
47>>$ 	IdOOOOO	 	27>>$ 	IdOOOO	s1   2D: AC#D: #C''D: *C'+D: :6E0boolc                    |                                  o<|                                 j        dk    o|                                 d d         dk    S )Ni      s   PNG

)rQ   statst_size
read_bytes)r   s    r   	png_validr\   =   sC    ;;==iTYY[[047iDOO<M<Mbqb<QUi<iir   intc                 d   t          j        t                              d                    t	          d          } t	          d          }t	          d          }t	          d          }fdt
                                          D             }fdt          D             }t          j        |                     d                    }t          j        |                    d                    }t          j        |                    d                    }|                    d	          d
k    s|                    d          durt          d          |                    d          }	d |
                                D             }
|                    d          |
k    rt          d          |                    d          |                    d          k    s|                    d          |	k    rt          d          |                    d          dus|                    d          |	k    rt          d          |                    d          t          |          k    rt          d          |                    d          durt          d          t                                          st          d          d |g|
                                D             }|rt          d|           g }dD ]}||         }|j                            dd            t           j        t%          t                    d!|d"         |         d#t%          |          d$d%d&d'd(d)d*d+g}t'          j        |ddd,-          }|j        d.k    st-          |          s)t          | d/|j         d0|j        d1d                     |                    |t%          |          t          |          |                                j        dd2           t7          |d3d|	|
t%          |          t          |          |ddt8          j                            t8          j        j                                                   d4
           d5|d	<   d|d<   ||d6<   t8          j                            t8          j        j                                                   |d7<   t7          ||           d8d|	|
t%          |          t          |          |ddt8          j                            t8          j        j                                                   d9d:}t7          ||           tC          t          j"        |d	         dtG          |          t%          |          d;d<                     d.S )=Nr=   encodingpromotion_receiptimage_prompts#image_prompt_reconciliation_receiptartwork_generation_receiptc                8    i | ]\  }}|t          |          S  r3   ).0rI   r&   projects      r   
<dictcomp>zmain.<locals>.<dictcomp>G   s)    WWWidCt^GS11WWWr   c                2    i | ]}|t          |          S rf   rg   )rh   r&   ri   s     r   rj   zmain.<locals>.<dictcomp>H   s%    MMMsnWc22MMMr   status	completedverifiedTz#promotion is absent or not verifiedcanon_sha256c                x    i | ]7}t          |                    t                              t          |          8S rf   )r   r/   r-   r   rh   r   s     r   rj   zmain.<locals>.<dictcomp>P   s6    XXXTs4##D))**F4LLXXXr   authority_hashesz%image prompt authority drift detectedsource_candidate_sha256candidate_sha256source_canon_sha256z-image prompts are stale for current promotionz.image prompt reconciliation is absent or staleprompt_manifest_sha256z2image prompt manifest changed after reconciliationimage_api_calledFz.image prompt manifest already marked as calledz%configured image generator is missingc                T    g | ]%}|                                 t          |          &S rf   )rQ   r   rq   s     r   
<listcomp>zmain.<locals>.<listcomp>^   s+    YYYd4;;==YD		YYYr   zGartwork outputs already exist and require explicit audit/invalidation: r   r6   z--promptpromptsz--outputz--n1z--detailhighz--formatpngz	--timeout600i  )textcapture_outputtimeoutr   z generation failed: exit=z	; stderr=i)kindr   r   bytespng_signature_verifiedrunning)
rl   rn   ru   rr   prompt_manifestrv   	generatedvisual_review_requiredorientation_gate_required
updated_at/generated_pending_visual_and_orientation_reviewr   generated_at/completed_pending_visual_and_orientation_reviewzsha256 streaming 8 MiB)rl   rn   ru   rr   r   rv   r   r   r   completed_athash_method)rl   rn   generated_countreceiptr:   )$rD   loadsPROJECT_MANIFEST	read_textr3   TARGET_KEYSitemsAUTHORITY_KEYSr)   r+   valuesr   	GENERATORis_filerB   rC   sys
executabler   
subprocessrun
returncoder\   stderrappendrY   rZ   rU   datetimenowtimezoneutc	isoformatprintrE   len)promotion_pathprompts_pathreconciliation_pathreceipt_pathtargets	authority	promotionrz   reconciliation
canon_hashcurrentexistingr   r&   outputcommandrm   r   ri   s                     @r   mainr   A   s   j)33W3EEFFG#G-@AAN!'?;;L(2WXX!'+GHHLWWWW;CTCTCVCVWWWGMMMMnMMMI
>33W3EEFFIj///AABBGZ 3 = =w = O OPPN}}X+--z1J1JRV1V1V@AAA~..JXXYEUEUEWEWXXXG{{%&&'11BCCC{{,--?Q1R1RRRV]VaVabwVxVx  }G  WG  WGJKKK*%%T11^5G5G5W5W[e5e5eKLLL233vl7K7KKKOPPP{{%&&e33KLLL DBCCCYY|&Ggnn6F6F&GYYYH qoemoopppI5  D4888NC	NNJ	8J38OFUCV{E

 N7dTWXXX	1$$If,=,=$jj1EjjPYP`afagagPhjj   	Vv[[]]*d
 
 	 	 	 	LU: 'C<M<M&,\&:&:&*"+//0A0EFFPPRR#
 #
 	 	 	 	 JGH"&G$GK&/33H4E4IJJTTVVGNg&&&CQV)w|,,|H\H\$%) )--h.?.CDDNNPP/ G g&&&	$*(#y>>c,6G6G        1r   __main__failedFz: )rl   rn   error	failed_atr=   r_   rd   r   )file)r   r   r   r   )r$   r%   r&   r   r   r   )r   r   r1   r%   r   r4   )r   r   r   rV   )r   r]   )(
__future__r   r   r   rD   rJ   r   r   rG   pathlibr   __file__r.   r7   r-   r   r   r   r   r   r3   rU   r\   r   __name__exit	Exceptionr2   typer   r   r   r   failurer   r   ri   r   rE   r   rf   r   r   <module>r      s   " " " " " "    				     



       tH~~'*88 Dabb	QQQ'%          j j j jN N N Nb z   ES		*33c33!*..x/@/DEEOOQQ
 

	 dj!1!;!;W!;!M!MNNGKw0LMMwWWWW 	 	 	D	jdju555CJGGGG s=   B   E7%AE24:D/.E2/D74E26D775E22E7