+
    8j                       R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIHtHt ^ RIHtHt ^ RIHt ^ RIHt ]! ]4      P1                  4       P2                  ^,          t]R,          tRtR	R
RR/t. R\Ot. R]Ot ! R R] 4      t!]! RR7       ! R R4      4       t"]! RR7       ! R R4      4       t#]! RR7       ! R R4      4       t$]! RR7       ! R R4      4       t%R R lt&R R lt'R R lt(R R  lt)R! R" lt*R# R$ lt+R% R& lt,R' R( lt-R) R* lt.R+ R, lt/R- R. lt0R/ R0 lt1R1 R2 lt2R3 R4 lt3R^R5 R6 llt4R7 R8 lt5R9 R: lt6R; R< lt7R= R> lt8R? R@ lt9RA RB lt:RC RD lt;RE RF lt<RG RH lt=RI RJ lt>RK RL lt?RM RN lt@RO RP ltARQ RR ltBRS RT ltCRU RV ltDRW RX ltER_RY RZ lltF]GR[8X  d   ]H! ]F! 4       4      hR# )`a&  Prepare and optionally assist TradingView Pine updates.

This tool is intentionally human-in-the-loop. It validates local Pine source,
copies the exact script text for paste, records an update manifest, and can open
TradingView in a normal visible browser session when Playwright is installed.
)annotationsN)asdict	dataclass)datetimetimezone)Path)Anyz.tradingview_e2ez"https://www.tradingview.com/chart/widthi  height  c                      ] tR t^+tRtRtR# )PineParseErrorz7Raised when a Pine script declaration cannot be parsed. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       C/Users/jameslopez/projects/TradingBot25/tools/tradingview_update.pyr   r   +   s    Ar   r   T)frozenc                  ^    ] tR t^/t$ R]R&   R]R&   R]R&   R]R&   R]R&   R]R	&   R]R
&   RtR# )PineScriptInfostrpathkindtitlez
int | Noneversionsha256int
line_count
char_countr   Nr   r   r   r   __annotations__r   r   r   r   r   r   /   s&    
I
IJKOOr   r   c                  V    ] tR t^:t$ R]R&   R]R&   R]R&   R]R&   ]R R	 l4       tR
tR# )CheckResult	list[str]commandr    
returncoder   stdoutstderrc                   V ^8  d   QhRR/# )   returnboolr   )formats   "r   __annotate__CheckResult.__annotate__B   s     $ $D $r   c                	     V P                   ^ 8H  # )    )r)   )selfs   &r   okCheckResult.okA   s    !##r   r   N)r   r   r   r   r$   propertyr6   r   r   r   r   r&   r&   :   s)    OKK$ $r   r&   c                  J    ] tR t^Ft$ R]R&   R]R&   R]R&   R]R&   R]R	&   R
tR# )PreparedUpdater   infolist[CheckResult]checksr   source_copymanifestr/   	clipboardr   Nr#   r   r   r   r:   r:   F   s    
NOr   r:   c                  6    ] tR t^Ot$ R]R&   R]R&   R]R&   RtR# )DoctorCheckr   namer/   r6   detailr   Nr#   r   r   r   rB   rB   O   s    
IHKr   rB   c                    V ^8  d   QhRRRR/# )r-   r   
str | Pathr.   r   r   )r0   s   "r   r1   r1   V   s     # #
 #s #r   c                    \        V 4      p  \        V P                  4       P                  \        4      4      #   \
         d    \        T P                  4       4      u # i ; iN)r   r   resolverelative_toREPO
ValueErrorr   s   &r   repo_relativerN   V   sL    :D#4<<>--d344 #4<<>""#s   +9 $A A c                    V ^8  d   QhRRRR/# )r-   r   r   r.   r   r   )r0   s   "r   r1   r1   ^   s     , ,D ,S ,r   c                &    V P                  R R7      # )utf-8encoding)	read_textrM   s   &r   rT   rT   ^   s    >>7>++r   c               $    V ^8  d   QhRRRRRR/# )r-   sourcer   	call_namer.   z
str | Noner   )r0   s   "r   r1   r1   b   s!      # # * r   c                   \         P                  ! R V R2V 4      pV'       g   R# VP                  4       ^,
          p^ pRpRp\        V\	        V 4      4       F  pW,          pV'       d!   V'       d   RpMVR8X  d   RpM	VR8X  d   RpK3  VR8X  d   RpK>  VR8X  d   V^,          pKP  VR8X  g   KY  V^,          pV^ 8X  g   Kk  WP                  4       V^,            u # 	  R# )	z\bz\s*\(NF\T"())researchendrangelenstart)	rV   rW   matchrb   depth	in_stringescapedidxchs	   &&       r   _extract_callri   b   s    III;e,f5EIIK!OEEIGUCK([ts!	9I3YQJE3YQJEzkkmS1W55# )$ r   c                    V ^8  d   QhRRRR/# )r-   callr   r.   r   )r0   s   "r   r1   r1      s     	A 	A 	A 	Ar   c                   \         P                  ! R V \         P                  4      pV'       d   VP                  ^4      # \         P                  ! RV \         P                  4      pV'       d   VP                  ^4      # \	        R4      h)z\btitle\s*=\s*"([^"]+)"z\(\s*"([^"]+)"z$Pine declaration has no string title)r]   r^   DOTALLgroupr   )rk   named
positionals   &  r   _extract_titlerq      sa    II0$		BE{{1~,dBII>J""
?
@@r   c                    V ^8  d   QhRRRR/# )r-   r   rF   r.   r   r   )r0   s   "r   r1   r1      s      Z N r   c                   \        V 4      p\        V4      p\        P                  ! R V\        P                  4      pV'       d   \        VP                  ^4      4      MRpR F#  p\        W%4      pV'       g   K  \        V4      p M	  \        R4      h\        \        V4      VVV\        P                  ! VP                  R4      4      P                  4       \!        VP#                  4       4      \!        V4      R7      # )z^\s*//@version\s*=\s*(\d+)\s*$Nz@Expected a top-level strategy(...) or indicator(...) declarationrQ   )r   r   r   r   r   r!   r"   )strategy	indicator)r   rT   r]   r^   	MULTILINEr    rn   ri   rq   r   r   rN   hashlibr   encode	hexdigestra   
splitlines)r   	pine_pathrV   version_matchr   r   rk   r   s   &       r   
parse_piner}      s    T
Iy!FII?VM-:c-%%a()G)V*4"4(E	 * _``9%~~fmmG45??Av((*+v; r   c                    V ^8  d   QhRRRR/# )r-   r(   r'   r.   r&   r   )r0   s   "r   r1   r1      s       { r   c                    \         P                  ! V \        R R RR7      p\        V VP                  VP
                  VP                  R7      # )TF)cwdcapture_outputtextcheck)r(   r)   r*   r+   )
subprocessrunrK   r&   r)   r*   r+   )r(   results   & r   run_commandr      sH    ^^F $$}}}}	 r   c                    V ^8  d   QhRRRR/# )r-   r{   rF   r.   r<   r   )r0   s   "r   r1   r1      s     	 	Z 	,= 	r   c                   \        V 4      p \        \        P                  R \	        V 4      .4      .pV P                  4       \        R,          P                  4       8X  d+   VP                  \        \        P                  R.4      4       V# )ztools/check_pine_duplicates.pyz*strategies/strategy_activation_scores.pineztools/check_pine.py)r   r   sys
executablerN   rI   rK   append)r{   r=   s   & r   run_preflightr      sn    YIS^^%E}U^G_`aF t&RR[[]]k3>>3H"IJKMr   c                    V ^8  d   QhRRRR/# )r-   r   r   r.   r/   r   )r0   s   "r   r1   r1      s      C D r   c                    \         P                  ! R 4      '       g   R#  \        P                  ! R .V RRR7       R#   \        P                   d     R# i ; i)pbcopyFT)inputr   r   )shutilwhichr   r   CalledProcessError)r   s   &r   copy_to_clipboardr      sL    <<!!zDE  (( s   = AAc               $    V ^8  d   QhRRRRRR/# )r-   out_dirr   r;   r   r.   r   )r0   s   "r   r1   r1      s!     8 84 8~ 8$ 8r   c                    \         P                  ! R RVP                  4      P                  R4      ;'       g    RpV \	        4        RV R2,          # )[^A-Za-z0-9_.-]+_pine_script.json)r]   subr   strip	timestamp)r   r;   
safe_titles   && r   manifest_pathr      sF    +S$**=CCCHYYMJ	}Aj\777r   c                   V ^8  d   QhRR/# )r-   r.   r   r   )r0   s   "r   r1   r1      s     A A3 Ar   c                 h    \         P                  ! \        P                  4      P	                  R 4      # )z%Y%m%dT%H%M%SZ)r   nowr   utcstrftimer   r   r   r   r      s!    <<%../?@@r   c                    V ^8  d   QhRRRR/# )r-   valuer   r.   r   )r0   s   "r   r1   r1      s     K K3 K3 Kr   c                d    \         P                  ! R RV 4      P                  R4      ;'       g    R# )r   r   capture)r]   r   r   r   s   &r   slugifyr      s)    66%sE288=JJJr   c               8    V ^8  d   QhRRRRRRRRR	RR
RRRRR/# )r-   r   r   r;   r   r=   r<   r@   r/   browser_openedplaywright_openedr>   r.   r   )r0   s   "r   r1   r1      sX     , ,,
, , 	,
 , , , 
,r   c                l   V P                  R R R7       R\        P                  ! \        P                  4      P                  4       R\        V4      R\        V4      RR\        RVP                  RR /R	V Uu. uFG  pR
VP                  RVP                  RVP                  RVP                  R R RVP                  R R /NKI  	  upRRVRVRV/RRVP                   RVP                  : R2RRRR./p\!        W4      p	V	P#                  \$        P&                  ! V^R R7      R,           RR7       V	# u upi )!Tparentsexist_ok
created_atscriptr>   tradingview	chart_urltarget_namehuman_review_requiredlocal_checksr(   r)   r6   stdout_tailNstderr_tailactionscopied_to_clipboardopened_default_browseropened_playwright_browserverification_stepsz5Open TradingView Pine Editor and select the existing z named .zkPaste the clipboard contents, save/update the script, and confirm TradingView shows no Pine compile errors.zUVisually inspect the chart/strategy tester for the expected script name and behavior.zpIf the script compiles, mark the relevant local sentinel, for example: python3 tools/check_pine.py --mark-valid.zXAttach screenshots or exported trades/CSV to future parity checks when behavior changes.indent	sort_keys
rQ   rR   i`)mkdirr   r   r   r   	isoformatr   rN   TRADINGVIEW_CHART_URLr   r(   r)   r6   r*   r+   r   r   
write_textjsondumps)
r   r;   r=   r@   r   r   r>   r   payloadr   s
   &&&&&&&   r   write_manifestr      sS    MM$M.hll8<<0::<&,}[1.4::#T

 	  	
   5==e..ehhu||EF3u||EF3  	
 	!9$n'):

 	CDII;gVZV`V`Uccdeyc~f
1G@ 'DOODJJwqDADHSZO[K3	
s   7AD1c               $    V ^8  d   QhRRRRRR/# )r-   r   r   urlr   r.   r/   r   )r0   s   "r   r1   r1     s!      T   r   c                    ^ RI Hp T R,          pTP                  RRR7       T! 4       ;_uu_ 4       pTP                  P                  \        T4      R\        R7      pTP                  '       d   TP                  ^ ,          MTP                  4       pTP                  TRRR	7       \        R
4       T R,          pTP                  RRR7       TR\        4        R2,          pTP                  \        T4      RR7       \        R\        T4       24       TP!                  4        RRR4       R#   \         d     R# i ; i  + '       g   i     R# ; i)r4   sync_playwrightFplaywright-profileTr   headlessviewportdomcontentloaded`  
wait_untiltimeoutzITradingView is open. Press Enter here after you finish/save the update...screenshotstradingview_.pngr   	full_pagezScreenshot saved: N)playwright.sync_apir   ImportErrorr   chromiumlaunch_persistent_contextr   DEFAULT_VIEWPORTpagesnew_pagegotor   r   
screenshotprintrN   close)	r   r   r   profile_dirpcontextpagescreenshot_dirscreenshot_paths	   &&       r   open_playwright_browserr     s-   7 00KdT2			a**66% 7 

 $+===w}}Qg6F6F6H		#"4f	EYZ =0TD9(\)+d+KKS1TB"=#A"BCD 
 )  
 
	 s   D1 C4E1E ?E E	c               (    V ^8  d   QhRRRRRRRR/# )r-   r   r   r;   r   rV   r   r.   r   )r0   s   "r   r1   r1   !  s(      t > 3 4 r   c                   V R ,          pVP                  RRR7       V\        4        R\        VP                  4       R2,          pVP	                  VRR7       VR\        VP                  4       R2,          pVP	                  VRR7       V# )rV   Tr   r   z.pinerQ   rR   latest_)r   r   r   r   r   )r   r;   rV   
source_dirsource_pathlatest_paths   &&&   r   write_source_copyr   !  s    8#JTD1)+a

0C/DEJJK6G4)<(=UCCK6G4r   c               0    V ^8  d   QhRRRRRRRRRRR	R
/# )r-   piner   r   r   no_clipboardr/   r   r   r.   r:   r   )r0   s   "r   r1   r1   ,  sD      
  	
  r   c           	     L   \        V 4      P                  4       '       g   \        V ,          P                  4       M
\        V 4      p\	        V4      p\        V4      p\        V4      pR p	V'       g   \        V4      p	\        WV4      p
\        WWyW4V
4      p\        VVV
VV	R7      # )F)r;   r=   r>   r?   r@   )r   is_absoluterK   rI   r}   r   rT   r   r   r   r:   )r   r   r   r   r   r{   r;   r=   rV   r@   r>   r?   s   &&&&&       r   stage_updater   ,  s     04Dz/E/E/G/G%%'TRVZIi D9%Fy!FI%f-	#G6:KgVcnoH r   c                    V ^8  d   QhRRRR/# r-   argszargparse.Namespacer.   r    r   )r0   s   "r   r1   r1   G  s     % %- %# %r   c                    ^ RI Hp \	        T P
                  4      pTR,          pTP                  RRR7       TR\        4        R2,          pT! 4       ;_uu_ 4       pTP                  P                  RR7      pTP                  \        R	7      pTP                  R
RR7       TP                  4       pTP                  \        T4      RR7       TP!                  4        RRR4       RXR8H  RTR\#        T4      /p	\        \$        P&                  ! T	^RR7      4       T	R,          '       d   ^ # ^#   \         d    \        R4        ^# i ; i  + '       g   i     Lv; i)r4   r   IPython Playwright is not installed. See docs/tradingview_e2e_workflow.md.r   Tr   smoke_r   r   r   z^data:text/html,<title>tradingview-e2e-smoke</title><body><h1>TradingView E2E smoke</h1></body>r   )r   r   Nr6   ztradingview-e2e-smoker   r   r   )r   r   r   r   resolve_out_dirr   r   r   r   launchr   r   r   r   r   r   r   rN   r   r   )
r  r   r   r   r   r   browserr   r   r   s
   &         r   playwright_smoker  G  s>   7
 dll+G},N5$	}D'AAO			a**##T#2)9:		:) 	 	

 

S1TB 
 	e..mO4G
 
$**WQ$
781$1$7  YZ 
	s   D0 BE0E
	E
E	c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r-   r=   zlist[DoctorCheck]rC   r   r6   r/   rD   r.   Noner   )r0   s   "r   r1   r1   h  s8     @ @. @c @t @S @UY @r   c                >    V P                  \        WVR 7      4       R# ))rC   r6   rD   N)r   rB   )r=   rC   r6   rD   s   &&&&r   add_doctor_checkr  h  s    
MM+4v>?r   c                    V ^8  d   QhRRRR/# )r-   pathsz
list[Path]r.   Path | Noner   )r0   s   "r   r1   r1   l  s     M Mz Mk Mr   c                    V  Uu. uF4  qP                  4       '       g   K  VP                  4       '       g   K2  VNK6  	  ppV'       g   R # \        VR R7      # u upi )Nc                N    V P                  4       P                  V P                  3# rH   )statst_mtimerC   rM   s   &r   <lambda>latest_file.<locals>.<lambda>p  s    499;+?+?*Kr   )key)existsis_filemax)r  r   existings   &  r   latest_filer  l  sB    !&K++-DLLNHKxKLL Ls   AAAc               $    V ^8  d   QhRRRRRR/# )r-   rootr   patternr   r.   r  r   )r0   s   "r   r1   r1   s  s!     1 1d 1S 1[ 1r   c                H    \        \        V P                  V4      4      4      # rH   )r  listglob)r!  r"  s   &&r   latest_globr&  s  s    tDIIg./00r   c                    V ^8  d   QhRRRR/# )r-   r   r  r.   zdict[str, Any] | Noner   )r0   s   "r   r1   r1   w  s       )> r   c                    V '       g   R #  \         P                  ! V P                  RR7      4      #   \         P                   d     R # i ; i)NrQ   rR   )r   loadsrT   JSONDecodeErrorrM   s   &r   load_json_filer+  w  s?    zz$..'.:;; s   %2 A
Ac                    V ^8  d   QhRRRR/# r  r   )r0   s   "r   r1   r1     s     #% #%# #% #%r   c                   \        V P                  4      p\        VR 4      ;'       g    \        VR4      p\        VR4      p\        VR4      p\        VR,          R4      p\        VR,          R4      p\        VR,          R	4      p\        V4      p\        V4      p	\        V4      p
T
;'       g    T	;'       g    Tp\	        V\
        4      '       d(   \	        VP                  R
4      \
        4      '       d   TMTpRVP                  4       R\        V4      RV'       d   \        V4      MRRV'       d   \        V4      MRRV'       d   \        V4      MRRV'       d   \        V4      MRRV'       d   \        V4      MRRV'       d   \        V4      MRR\	        V\
        4      '       d   VP                  R4      MRR\	        V\
        4      '       dG   \	        VP                  R
4      \
        4      '       d"   VP                  R
/ 4      P                  R4      MRR\	        V
\
        4      '       d   V
P                  R4      MR/p\        \        P                  ! V^RR7      4       VR,          '       d   ^ # ^# )z*_MLPScores.jsonz*.jsonz*_capture.jsonz*_manual_update.jsonr   z*.png	page_textz*.txtrV   z*.piner   r6   r   latest_manifestNlatest_capturelatest_manual_updatelatest_screenshotlatest_textlatest_sourcelatest_result_oklatest_script_titler   manual_update_verificationverificationTr   )r	  r   r&  r+  
isinstancedictgetr  rN   r   r   r   )r  r   r?   r   manual_updater   r   rV   manifest_payloadcapture_payloadmanual_payloadlatest_payloadtitle_sourcer   s   &             r   statusrB    s   dll+G7$67YY;wPX;YH'#34G)?@MW}4g>Jw,g6D8+X6F%h/$W-O#M2N#JJJJ:JN>4((Z8J8J88TVZ-[-[ " 
 	gnn=)h=2DG-0m <SW*]:6$d}T*&v.d
>SW8X8XN..t4^b,--*\=M=Mh=WY]2^2^ Xr*..w7$JWegkLlLln&8&8&HrvG" 
$**WQ$
781$1$r   c                    V ^8  d   QhRRRR/# r  r   )r0   s   "r   r1   r1     s     ^% ^%# ^% ^%r   c                   . p\        V P                  4      P                  4       '       g   \        V P                  ,          M\        V P                  4      p\	        VR \        P                  4       \        \        4      4       \	        VR\        R,          P                  4       R4       \	        VRR\        R,          P                  RR7      9   R4        \        V4      p\	        VRR	VP                   R
VP                  : 24       VP                  4       '       dd   \        V4      pV Uu. uF  qfP                  '       d   K  VNK  	  pp\	        TRV'       * V'       g   RMRP                  R V 4       4      4       M\	        VRRR\        V4       24        \         P"                  P%                  R4      p\	        VRR	V4        ^ RIHp	 \	        VRR	R4       \/        V P0                  4      p
RpRpRpV	'       Ed   V P2                  '       g   V P4                  '       Edn   V
R,          pV
R,          pVP7                  R	R	R7       VP7                  R	R	R7        V	! 4       ;_uu_ 4       pV P2                  '       d   VR\9        4        R2,          pVP:                  P=                  R	R7      pVP?                  \@        R7      pVPC                  R4       VP                  4       pVPE                  \        V4      R	R7       VPG                  4        \	        VR VR!8H  \        V4      4       V P4                  '       EdJ   \9        4       pVR"V R2,          pVR"V R#2,          pVP:                  P=                  R	R7      pVP?                  \@        R7      pVPC                  \H        R$V PJ                  R%7       V PL                  '       d   VPO                  V PL                  4       VPQ                  R&4      PS                  R'R(7      pVPE                  \        V4      R	R7       VPG                  4        VPU                  VRR7       R)V9   ;'       d    R*V9   ;'       g    R+V9   p\	        VR,V\        V4       R\        V4       24       RRR4       R\V        ;QJ d    R. V 4       F  '       d   K   RM	  R	M! R. V 4       4      R/V'       d   \Y        V4      MRR0V Uu. uF  p\Y        V4      NK  	  upR1V'       d   \        V4      MRR2V'       d   \        V4      MRR3V'       d   \        V4      MR/p\[        \\        P^                  ! V^R	R47      4       VR,          '       d   ^ # ^#   \         d%   pRp\	        TRR\        T4      4        Rp?ELRp?ii ; iu upi   \         P"                  P&                   d    \	        TRRR4        ELi ; i  \,         d%   p\	        TRR\        T4      4       Rp	 Rp?EL%Rp?ii ; i  + '       g   i     EL; i  \         d#   p\	        TR-R\        T4      4        Rp?ELRp?ii ; iu upi )5repozrequirements-e2ezrequirements-e2e.txtzgitignore-artifactsz.tradingview_e2e/z
.gitignorerQ   rR   z
pine-parseT NFzpine-preflightr6   z; c              3  v   "   T F/  pR P                  VP                  4       RVP                   2x  K1  	  R# 5i)rF   -> N)joinr(   r)   .0r   s   & r   	<genexpr>doctor.<locals>.<genexpr>  s3     -untej%--1H0IeN^N^M_.`nts   79zmissing 
playwrightzplaywright-pythonznot installedr   zplaywright-importr   r.  r   doctor_browser_r   r  r  z6data:text/html,<title>doctor</title><h1>doctor ok</h1>r   zbrowser-launchdoctordoctor_tradingview_.txtr   r   body  r   
Indicators	WatchlistPine Editorztradingview-renderzbrowser-runtimec              3  8   "   T F  qP                   x  K  	  R # 5irH   r6   rJ  s   & r   rL  rM    s     /u((s   r   r=   browser_screenshottradingview_screenshottradingview_textr   )0r   r   r   rK   r  r  r   rT   r}   r   r   	Exceptionr   r6   rI  rN   	importlibmetadatar   PackageNotFoundErrorr   r   r   r	  r   r  r   r   r   r   r
  r   r   r   r   r   r   
timeout_mswait_mswait_for_timeoutlocator
inner_textr   allr   r   r   r   )r  r=   r{   r;   exc	preflightr   failedr   r   r   r[  r\  r]  r   text_dirr   r  r   r   stampr   renderedr   s   &                       r   rP  rP    sj    "F(,TYY(C(C(E(Etyy 4PTPYPY?IVVT[[]CI>V/$9O2O1W1W1Y[qrV24GDS_L_KjKjt{KjK|4|  R  S@)$t		{!DJJ>5RS
 !),	%.?YEhh%%Y?JDDII-unt-u$u		
 	!15H]S\E]D^:_`N$$,,\:!4dGDB7
 	!4dDAdll+G!DLLLD,<,<,< =0[(TD9td3!	I ""a<<<)7OIK=X\:])]&jj///>G"++5E+FDIIVW JJLEOO-?)@DOQMMO$V-=u?PR_`rRst###%KE-;@STYSZZ^>_-_*'/4Gwd2S'S$jj///>G"++5E+FDII3@R\`\k\kIl|||--dll;<</::4:HDOO-C)DPTOUMMO$//w/G+t3ff9L9e9eP]aePeH$, ()?@AMRbDcCde	3 #F 	cc//ccc///t$f5fU6%=f5CUm,>?[_ Ka-0F"Ggk?OM*:;UYG 
$**WQ$
781$1$g  @uc#h??@ @ 22 N!4e_MN
  !4eSXF  #"">  	IV%6s3xHH	I 6s   3U2 1V$	V$ -V) W $X# 3CXDXX%+XX# &Y2V!=VV!)-WWX(XXX 	X#  X# #Y.YYc                    V ^8  d   QhRRRR/# r  r   )r0   s   "r   r1   r1     s     0 0( 0S 0r   c                    ^ RI Hp \	        T P
                  4      pTR,          pTR,          pTR,          pTP                  RRR7       TP                  RRR7       \        T P                  ;'       g    T P                  4      p\        4       pYG RT R	2,          pYW RT R
2,          p	Y' RT R2,          p
T! 4       ;_uu_ 4       pTP                  P                  \        T4      T P                  '       * \        R7      pTP                   '       d   TP                   ^ ,          MTP#                  4       pTP%                  T P                  T P&                  T P(                  R7       T P*                  '       d   TP-                  T P*                  4       TP/                  4       pT P0                  '       d"   TP3                  R4      P5                  RR7      MRpTP7                  \        T4      RR7       TP9                  4        RRR4       T P0                  '       d   T	P;                  XRR7       RRRT P                  RXR\=        T4      RT P0                  '       d   \=        T	4      MRRT P                  /pT
P;                  \>        P@                  ! T^RR7      R,           RR7       \        \>        P@                  ! T^RR7      4       ^ #   \         d    \        R4        ^# i ; i  + '       g   i     L; i)r4   r   r  r   r   r.  Tr   r   r   rR  z_capture.jsonr   r   rS  rT  rU   r   NrQ   rR   r6   r   r   r   r   headedr   r   )!r   r   r   r   r	  r   r   r   labelr   r   r   r   r   rq  r   r   r   r   r   rb  rc  rd  r   	save_textre  rf  r   r   r   rN   r   r   )r  r   r   r   r   rk  rr  rl  r   	text_pathmetadata_pathr   r   r   r   visible_textr   s   &                r   capture_urlrw    sm   7
 dll+G00K},N$H5NN4$N/DJJ**$((+EKE$%'==OWAeWD11Iq}==M			a**66_% 7 

 $+===w}}Qg6F6F6H		$((t	P<<<!!$,,/

HLt||F+66t6D\^S1TB 
 ~~~\G< 	dtxxmO4DNNNi($++G TZZTJTQ\cd	$**WQ$
78[  YZ" 
	s+   K 
B3K1><K1;AK1K.-K.1L	c                    V ^8  d   QhRRRR/# r  r   )r0   s   "r   r1   r1   :  s     6 6+ 6 6r   c                l    ^ RI Hp \	        T P
                  4      pTR,          pTR,          pTR,          pTP                  RRR7       TP                  RRR7       \        4       pTRT R	2,          pTRT R
2,          pTRT R2,          p	T! 4       ;_uu_ 4       p
T
P                  P                  \        T4      T P                  '       * \        R7      pTP                  '       d   TP                  ^ ,          MTP                  4       pTP                  T P                   T P"                  T P$                  R7       T P&                  '       d   \)        R4       T P*                  '       d   TP-                  T P*                  4       TP/                  4       pTP1                  R4      P3                  RR7      pTP5                  \        T4      RR7       TP7                  4        RRR4       TP9                  XRR7       TP;                  4       p\<         Uu. uF  pTT9   g   K  TNK  	  ppR" Uu. uF  pTT9   g   K  TNK  	  ppRRRT P                   RXR\?        T4      R\?        T4      R\?        T4      R\A        T4      RTRTR\A        T4      ;'       d    T'       * /
pT	P9                  \B        PD                  ! T^RR 7      R!,           RR7       \        \B        PD                  ! T^RR 7      4       ^ #   \         d    \        R4        ^# i ; i  + '       g   i     EL:; iu upi u upi )#r4   r   r  r   r   r.  Tr   profile_status_r   rR  r   r   r   z`Use the visible browser to sign in or inspect TradingView, then press Enter to capture status...rS  rT  rU  r   NrQ   rR   r6   r   r   r   r   r   login_prompt_detectedlogin_promptscontrols_seenprofile_ready_hintr   r   )rV  rX  SavePublish)#r   r   r   r   r	  r   r   r   r   r   r   rq  r   r   r   r   r   r   rb  wait_for_userr   rc  rd  r   re  rf  r   r   r   lowerLOGIN_PROMPT_PATTERNSrN   r/   r   r   )r  r   r   r   r   rk  rl  r   rt  ru  r   r   r   r   rv  
lower_textr"  r|  itemr}  r   s   &                    r   profile_statusr  :  s   7
 dll+G00K},N$H5NN4$N/KE$t'DDO_UG488Iwe<<M			a**66_% 7 

 $+===w}}Qg6F6F6H		$((t	Ptu<<<!!$,,/

||F+66t6DS1TB 
" 8##%J,A[,AWPZEZWW,AM[&Vo&VdZ^bnZnTT&VModtxx}[1mO4i(m!4d=1GG-6GG TZZTJTQ\cd	$**WQ$
78g  YZ  
		& \osC   K; B3LL/A8L	L,(L,4	L1L1;LLL)	c                    V ^8  d   QhRRRR/# r  r   )r0   s   "r   r1   r1   s  s     E* E** E*s E*r   c                	    ^ RI Hp \	        T P
                  4      p\        T P                  Y P                  4      p\        TP                  TP                  TP                  TP                  4       \        R\        TP                  4       24       \         ;QJ d&    R TP                   4       F  '       g   K   RM	  RM! R TP                   4       4      '       d   ^# TR,          pTR,          pTR	,          pTP#                  RRR
7       TP#                  RRR
7       \%        T P&                  ;'       g    RTP                  P(                   24      p\+        4       pYX RT R2,          p	Yh RT R2,          p
Y( RT R2,          pT P,                  ;'       g    TP                  P(                  .pT P.                  ;'       g    \0        p\        4        \        R4       \        RTP                  P2                   RTP                  P(                   24       \        R\        TP                  4       24       \        R4       \        R4       T! 4       ;_uu_ 4       pTP4                  P7                  \9        T4      R\:        R7      pTP<                  '       d   TP<                  ^ ,          MTP?                  4       pTPA                  T PB                  T PD                  T PF                  R7       \I        R4       T PJ                  '       d   TPM                  T PJ                  4       TP)                  4       pTPO                  R4      PQ                  RR7      pTPS                  \9        T	4      RR7       TPU                  4        RRR4       T
PW                  XRR7       \Y        TY4      pR TR ,          R!T PB                  R"XR#\[        TP                  4      R$\        TP                  4      R%\        TP                  4      R&\        T	4      R'\        T
4      R(TR)TR*T/pTPW                  \\        P^                  ! T^RR+7      R,,           RR7       \        \\        P^                  ! T^RR+7      4       TR ,          '       d   ^ # ^#   \         d    \        R4        ^# i ; i  + '       g   i     EL'; i)-r4   r   r    Source copy: c              3  B   "   T F  qP                   '       * x  K  	  R # 5irH   rZ  rJ  s   & r   rL   guided_update.<locals>.<genexpr>       
5_Exx<<_   TFr   r   r.  r   zmanual-update-r   r   rR  z_manual_update.jsonz,A visible browser will open. In TradingView:z.  1. Open Pine Editor and select the existing z: z*  2. Paste from clipboard, or paste from: zM  3. Save/update the script and confirm the editor reports no compile errors.zDReturn here and press Enter after the save/compile step is complete.r   r   z/Press Enter to capture verification evidence...rS  rT  rU  r   NrQ   rR   r6   r   
page_titler   r?   r>   r   r   r8  expectedrejectedr   r   )0r   r   r   r   r	  r   r   r   r   print_summaryr;   r=   r?   r@   rN   r>   anyr   r   rr  r   r   expectrejectDEFAULT_REJECT_PATTERNSr   r   r   r   r   r   r   r   r   r   rb  r   rc  rd  re  rf  r   r   r   verify_text_contentr   r   r   )r  r   r   preparedr   r   rk  rr  rl  r   rt  ru  r  r  r   r   r   r   rv  r8  r   s   &                    r   guided_updater  s  s   7
 dll+GDIIw0A0ABH(--(2C2CXEWEWX	OM(*>*>?@
AB
s
5X__
5sss
5X__
55500K},N$H5NN4$N/DJJHHN8==3F3F2G"HIEKE$%'==OWAeWD11Iq/BCCM{{33x}}223H{{555H	G	
89	:8==;M;M:NbQYQ^Q^QdQdPe
fg	6}XEYEY7Z6[
\]	
YZ	
PQ			a**66% 7 

 $+===w}}Qg6F6F6H		$((t	P?@<<<!!$,,/

||F+66t6DS1TB 
  8&|XHLl4 txxe&'M("3"34}X%9%9:mO4i(HHG TZZTJTQ\cd	$**WQ$
78T""1))E  YZB 
		s   R (D(R.R+*R+.R?	c               (    V ^8  d   QhRRRRRRRR/# )r-   r   r   r  r'   r  r.   zdict[str, Any]r   )r0   s   "r   r1   r1     s)      c Y ) P^ r   c                    V Uu. uF  q3'       g   K  W09  g   K  VNK  	  ppV Uu. uF  q3'       g   K  W09   g   K  VNK  	  ppR V'       * ;'       d    V'       * RVRV/# u upi u upi )r6   missing_expectedfound_rejectedr   )r   r  r  r  r  r  s   &&&   r   r  r    sr    )1OTd>NO'/Ixt4dDLddxNI""99>'9,.  PIs   	A!A!A!	A&A&A&c                    V ^8  d   QhRRRR/# r  r   )r0   s   "r   r1   r1     s     $ $( $S $r   c                   \        V P                  4      pVP                  4       '       g   \        V,          pVP	                  R R7      pV P
                  ;'       g    \        p\        W P                  V4      p/ VCR\        V4      RV P                  RV/Cp\        \        P                  ! V^RR7      4       VR,          '       d   ^ # ^# )rQ   rR   r   r  r  Tr   r6   )r   r   r   rK   rT   r  r  r  r  rN   r   r   r   )r  rt  r   r  r   r   s   &     r   verify_textr    s    TYYI  ""9$	0D{{555H {{H=F
i(DKKH	G 
$**WQ$
78t1#!#r   c                    V ^8  d   QhRRRR/# )r-   r   r   r.   r   r   )r0   s   "r   r1   r1     s     V V3 V4 Vr   c                    \        V 4      P                  4       '       g   \        V ,          P                  4       # \        V 4      # rH   )r   r   rK   rI   r   s   &r   r	  r	    s0    +/;+B+B+D+DD5L!!#U$u+Ur   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r-   r;   r   r=   r<   r?   r   r@   r/   r.   r  r   )r0   s   "r   r1   r1     s2       0A T ^b gk r   c                   V Uu. uF  qDP                   '       d   K  VNK  	  pp\        R V P                   RV P                  : 24       \        RV P                   24       \        RV P
                   24       \        R\        V4       24       \        RV'       d   RMR 24       \        4        V'       dV   \        R4       V F7  p\        R	RP                  VP                  4       R
VP                   24       K9  	  \        R4       R# \        R4       \        R	V P                   24       \        4        \        R4       \        \        P                  ! R^XR7      4       R# u upi )z Prepared TradingView update for rF  z  Source:   z  SHA-256:  z  Manifest: z  Clipboard: updatedznot availablezPreflight failed:z  rH  z*Fix these before pasting into TradingView.z=Preflight passed. Use the exact same TradingView script name:zNext human-in-the-loop step:zOpen TradingView, select the existing script with that name in Pine Editor, paste from the clipboard, save it, and visually confirm there are no compile errors.)r	   N)r6   r   r   r   r   r   rN   rI  r(   r)   textwrapfill)r;   r=   r?   r@   r   rj  s   &&&&  r   r  r    s"   !'8xxeeF8	,TYYKq
GH	L
$%	L
&'	Lx01
23	My)oF
GH	G!"EBsxx./tE4D4D3EFG :;MN4::, ,-hmmc
 	# 9s
   E,E,c                    V ^8  d   QhRRRR/# r  r   )r0   s   "r   r1   r1     s      $  r   c                $   \        V P                  4      p\        V P                  WP                  V P
                  V P                  4      p\        VP                  VP                  VP                  VP                  4       \        R \        VP                  4       24       \        ;QJ d&    R VP                   4       F  '       g   K   RM	  RM! R VP                   4       4      '       d   ^# RpV P
                  '       d   \         P
                  ! \"        4      pRpV P                  '       d$   \%        V\"        4      pV'       g   \        R4       V P
                  '       d   V'       g   ^# V P                  '       d   V'       g   ^# ^ # )r  c              3  B   "   T F  qP                   '       * x  K  	  R # 5irH   rZ  rJ  s   & r   rL  prepare.<locals>.<genexpr>  r  r  TFr  )r	  r   r   r   r   openplaywright_openr  r;   r=   r?   r@   r   rN   r>   r  
webbrowserr   r   )r  r   r  r   r   s   &    r   preparer    s	   dll+GDIIw0A0A499dNbNbcH(--(2C2CXEWEWX	OM(*>*>?@
AB
s
5X__
5sss
5X__
555Nyyy#)>?3G=RS ]^yyy$5r   c                    V ^8  d   QhRRRR/# r  r   )r0   s   "r   r1   r1     s      $  r   c                    \        V P                  4      p\        \        P                  ! \        V4      ^RR7      4       ^ # )r-   Tr   )r}   r   r   r   r   r   )r  r;   s   & r   inspectr    s,    dii D	$**VD\!t
<=r   c                   V ^8  d   QhRR/# )r-   r.   zargparse.ArgumentParserr   )r0   s   "r   r1   r1     s     p p- pr   c                    \         P                  ! \        R 7      p V P                  RRR7      pVP	                  RRR7      pVP                  RRR7       VP                  \        R	7       VP	                  R
RR7      pVP                  RRR7       VP                  R\        \        P                  \        4      4      R7       VP                  RRRR7       VP                  RRRR7       VP                  RRRR7       VP                  \        R	7       VP	                  RRR7      pVP                  RRR7       VP                  R\        R7       VP                  RRR7       VP                  R\        \        P                  \        4      4      R7       VP                  RRRR7       VP                  R\        RRR7       VP                  R \        R!R"7       VP                  R#. RJOR$R%7       VP                  R&R'. R(R)7       VP                  R*R'. R+R)7       VP                  \        R	7       VP	                  R,R-R7      pVP                  R\        \        P                  \        4      4      R7       VP                  \         R	7       VP	                  R.R/R7      pVP                  R0R1R7       VP                  R\        \        P                  \        4      4      R7       VP                  R2RR3R7       VP                  R4RR5R7       VP                  R\        R6R"7       VP                  R \        R!R"7       VP                  \"        R	7       VP	                  R7R8R7      pVP                  R\        \        P                  \        4      4      R7       VP                  \$        R	7       VP	                  R9R:R7      pVP                  R\        R7       VP                  RRR7       VP                  R\        \        P                  \        4      4      R7       VP                  R;RR<R7       VP                  R=RR>R7       VP                  R\        ^ RR7       VP                  R \        R!R"7       VP                  R#. RJOR$R%7       VP                  \&        R	7       VP	                  R?R@R7      p	V	P                  R\        R7       V	P                  R\        \        P                  \        4      4      R7       V	P                  R;RRAR7       V	P                  RBRRCR7       V	P                  R\        R6R"7       V	P                  R \        R!R"7       V	P                  R#. RJOR$R%7       V	P                  \(        R	7       VP	                  RDRER7      p
V
P                  RFRRGRH7       V
P                  R&R'. RIR)7       V
P                  R*R'. R+R)7       V
P                  \*        R	7       V # )K)descriptionr(   T)destrequiredr  z"Print parsed Pine metadata as JSON)helpr   zPath to a .pine script)funcr  z(Preflight and stage a TradingView updatez%Path to a .pine strategy or indicatorz	--out-dir)defaultz--no-clipboard
store_truez!Do not copy Pine source to pbcopy)actionr  z--openz-Open TradingView chart in the default browserz--playwright-openzVOpen a visible persistent Playwright browser and save a screenshot after manual reviewzmanual-updatezTStage Pine, open TradingView, wait for manual save, then capture and verify evidencez--urlz--labelrp  z	--wait-msr   zExtra wait before capture)typer  r  z--timeout-msr   )r  r  z--wait-untilr   )choicesr  z--expectr   zHString expected in the captured text. Defaults to the Pine script title.)r  r  r  z--rejectzKString that must not appear. Defaults to common Pine compile-error phrases.smokez2Verify Playwright can launch and save a screenshotrP  zCheck TradingView E2E readinessz--pinez#strategies/strategy_mlp_scores.pinez	--browserz*Launch a local headless browser smoke testz--tradingviewz)Capture TradingView chart render evidencei  rB  z*Summarize latest TradingView E2E artifactsr   z3Navigate to a URL and save screenshot/text metadataz--headedz,Show the browser instead of headless capturez--save-textz-Save visible body text next to the screenshotzprofile-statusz9Capture persistent TradingView profile readiness evidencez#Show the persistent browser profilez--wait-for-userz&Wait for Enter before capturing statuszverify-textz5Check captured text for expected and rejected stringsz--textz&Path to captured visible-text artifact)r  r  zHString that must appear in the captured text; repeat for multiple checks)commitr   loadnetworkidle)argparseArgumentParserr   add_subparsers
add_parseradd_argumentset_defaultsr  r   DEFAULT_OUT_DIRrJ   rK   r  r   r    r  r  rP  rB  rw  r  r  )parser
subparsersinspect_parserprepare_parserguided_parsersmoke_parserdoctor_parserstatus_parsercapture_parserprofile_parserverify_parsers              r   build_parserr    s   $$9F&&I&EJ**9;_*`N-EFW-**9;e*fN-TUS9T9TUY9Z5[\ 0LopDste   
 W-))c * M v,STw0EFy"5{C8S8STX8Y4Z[/Kno{dIde~CHE"  
 W	   Z	   M2((7k(lLk37R7RSW7X3YZ#34))(9Z)[Mx1VW{C8S8STX8Y4Z[{<Frs|Juv{dC~CHF+))(9e)fM{C8S8STX8Y4Z[F+**9;p*qN1FG	26S9T9TUY9Z5[\
<FtulIxy#qGbcS&IE"   
 [1**+;B}*~N1FGS9T9TUY9Z5[\
<Fkl 1,Muv#tDS&IE"   
 ^4))->u)vMx$=efW	   Z	   K0Mr   c                    V ^8  d   QhRRRR/# )r-   argvzlist[str] | Noner.   r    r   )r0   s   "r   r1   r1     s       3 r   c                Z    \        4       pVP                  V 4      pVP                  V4      # rH   )r  
parse_argsr  )r  r  r  s   &  r   mainr    s'    ^FT"D99T?r   __main__)zCannot compilezCompilation errorzError atzMismatched inputzSyntax errorzUndeclared identifierz-Could not find function or function reference)zsign inzlog inzsign upzjoin for free)FFrH   )Ir   
__future__r   r  rw   importlib.metadatar_  r   r]   r   r   r   r  r  dataclassesr   r   r   r   pathlibr   typingr   __file__rI   r   rK   r  r   r   r  r  rL   r   r   r&   r:   rB   rN   rT   ri   rq   r}   r   r   r   r   r   r   r   r   r   r   r  r  r  r&  r+  rB  rP  rw  r  r  r  r  r	  r  r  r  r  r  r   
SystemExitr   r   r   <module>r     s   #     	   
   ) '   H~''*++< T8T2   J BZ B $   $$ $ $ $   $  #,<	A2 	8
AK,^46%B@M1#%L^%B0f6rE*P$"V24pf z
TV
 r   