+
    #jF                    R   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHt ]P                  P                  ^ ]
! ]! ]4      P                  4       P                  4      4       ^ RIHtHtHtHtHtHtHt R R ltR R ltR	 R
 ltRR R llt]R8X  d   ]P6                  ! ]! 4       4       R# R# )u  
fetch_logs.py — Retrieve workflow execution diagnostics from a ComfyUI server.

When a workflow errors, the server's /history (local) or /jobs (cloud) entry
contains the full Python traceback. This script makes it easy to fetch by
prompt_id, with sensible formatting.

Usage:
    python3 fetch_logs.py <prompt_id>
    python3 fetch_logs.py <prompt_id> --host https://cloud.comfy.org
    python3 fetch_logs.py --tail-queue            # show currently queued/running jobs
)annotationsN)Path)DEFAULT_LOCAL_HOSTENV_API_KEY	emit_jsonhttp_getis_cloud_hostresolve_api_keyresolve_urlc          
     ,    V ^8  d   QhRRRRRRRRRR/# )	   hoststrheadersdict	prompt_idis_cloudboolreturn )formats   "d/opt/hermes-venv/lib/python3.14/site-packages/../../../skills/creative/comfyui/scripts/fetch_logs.py__annotate__r      s7      H  Hc  HD  HS  Ht  HX\  H    c          	        V'       d   \        V R V 2RR7      p\        WA^^R7      pVP                  ^8X  d    RRRVP                  4       RR/# \        V RV 2RR7      p\        WA^^R7      p VP                  4       pVP                  ^8X  d   V'       d	   RRRVRR
/# RRRVP                  RVP                  4       R,          /# \        V RV 2RR7      p\        WA^^R7      pVP                  ^8w  d(   RRRVP                  RVP                  4       R,          /#  VP                  4       p\        T\        4      '       d   Y&9  d@   RRRRR\        T\        4      '       d"   \        TP                  4       4      R,          /# . /# RRRYb,          RR/#   \         d     ELWi ; i  \         d    R	p EL;i ; i  \         d
    RRRR/u # i ; i)z/jobs/Tr   r   retriestimeoutokentrysourcez	/api/jobsz	/history/Nz/api/history_v2Fhttp_statusbodyNi  Nreasonznon-JSON responsezprompt_id not found in historyhistory_keys:N   Nz/history)
r
   r   statusjson	Exceptiontext
isinstancer   listkeys)r   r   r   r   urlrdatas   &&&$   r   fetch_history_entryr2      s   $& 4tDS1bA88s?dGQVVXxMM $)I; 7$GS1bA	668D 88s?t$x9JKKe]AHHfaffhtnMM
di	{3e
DCq"=Axx3e]AHHfaffhtnMM<vvx dD!!Y%:eX'GD$9O9OTYY[ 1" 5Y 	YUWY 	Y$(JGG1    	D	  <eX':;;<s5   F 0F+  F? F('F(+F<;F<?GGc               $    V ^8  d   QhRRRRRR/# )r   r   r   r   r   r   r   )r   s   "r   r   r   @   s!     3 3c 3D 3T 3r   c                    \        V R 4      p\        W!^^R7      p VP                  4       pRVP
                  RV/#   \         d    RTP	                  4       R,          /p L6i ; i)z/queuer   rawr$   r"   r1   )r
   r   r)   r*   r+   r(   )r   r   r/   r0   r1   s   &&   r   fetch_queuer6   @   sf    
dH
%Cq"=A'vvx 188VT22  'qvvx~&'s   < $A#"A#c                    V ^8  d   QhRRRR/# )r   r    r   r   r   )r   s   "r   r   r   J   s     ) )t ) )r   c                *   / pV P                  R4      ;'       g    / pVP                  R4      VR&   VP                  R4      VR&   VP                  R4      ;'       g    . p. VR&   V Fp  p\        V\        4      '       d@   \        V4      ^8  d0   V^ ,          V^,          reVR,          P	                  RVRV/4       KX  VR,          P	                  V4       Kr  	  . pV FU  p\        V\        4      '       g   K  \        V4      ^8  g   K-  V^ ,          R8X  g   K=  VP	                  V^,          4       KW  	  V'       d   WqR	&   R
V 9   d   V R
,          ;'       g    / p\        V\
        4      '       d   \        VP                  4       4      VR&   ^ p	VP                  4        F\  p
\        V
\
        4      '       g   K  V
P                  4        F-  p\        V\        4      '       g   K  V	\        V4      ,          p	K/  	  K^  	  WR&   V# . VR&   ^ VR&   V# )zJPull out the parts a human cares about: status, errors, traceback, timing.r(   
status_str	completedmessagesexecution_logtyper1   execution_errorerrorsoutputsoutput_node_idsoutput_count)getr,   r-   lenappendr   r.   values)r    diagr(   r;   msgmtypemdatar?   outtotalnode_outputvs   &           r   extract_diagnosticsrO   J   s   DYYx &&BFL1D

;/Dzz*%++HDc4  SX]q63q65!((&%)GH!((-  Fc4  SX]s1vAR7RMM#a&!  X EI$$"c4  &*388:&6D"#E"zz|!+t44$++-A!!T**Q .  , $)  K ')D"##$D Kr   c                    V ^8  d   QhRRRR/# )r   argvzlist[str] | Noner   intr   )r   s   "r   r   r   v   s     $@ $@ $@3 $@r   c                   \         P                  ! R R7      pVP                  RRRR7       VP                  R\        R7       VP                  RR	\         2R
7       VP                  RRRR7       VP                  RRRR7       VP                  V 4      p\        VP                  4      pV'       d   RV/M/ p\        VP                  4      pVP                  '       d"   \        \        VP                  V4      4       ^ # VP                  '       g   \        R\        P                   R7       ^# \#        VP                  WBP                  VR7      pVP%                  R4      '       g   \        V4       ^# VP&                  '       d   \        V4       ^ # \)        VR,          4      pVP%                  R4      VR&   VP                  VR&   \        V4       VP%                  R4      R9  d   ^ # ^# )z$Fetch workflow execution diagnostics)descriptionr   ?zprompt_id to look up)nargshelpz--host)defaultz	--api-keyzor set $)rW   z--raw
store_truez2Print the full history entry instead of the digest)actionrW   z--tail-queuez+Show currently running/pending jobs insteadz	X-API-Keyz2Error: prompt_id is required (or use --tail-queue))filer   r   r    r!   r9   >   error)argparseArgumentParseradd_argumentr   r   
parse_argsr	   api_keyr   r   
tail_queuer   r6   r   printsysstderrr2   rC   r5   rO   )rQ   pargsra   r   r   resrG   s   &       r   mainri   v   s   ,RSANN;c0FNGNN8%7N8NN;x}%=N>NN7<L  NNN>,E  G<<Ddll+G(/{G$RGTYY'H+dii12>>>BT
dii..8
TC774==#xxx#s7|,DWWX&DNDdO&j81?a?r   __main__)N)__doc__
__future__r   r]   r)   rd   pathlibr   pathinsertr   __file__resolveparent_commonr   r   r   r   r   r	   r
   r2   r6   rO   ri   __name__exitr   r   r   <module>rv      s    #   
  3tH~--/667 8   HF3)X$@N zHHTV r   