+
    5mjn                    L   ^ 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t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHtH t H!t!H"t"H#t# ^ R	I$H%t%H&t&H't' ^ R
I(H)t)H*t*H+t+ ^ RI,H-t-H.t.H/t/H0t0 ^ RI1H2t2 ^ RI3H4t4 ^ RI5H6t6 Rt7Rt8Rt9Rt:Rt;RRRRRR/t<]=! ]24      t>Rt?]P                  ! R4      tA]P                  ! R4      tB]! R4      tCRtDRtE]P                  ! R4      tF]G! 0 Rm4      tHRtI]J! ]2P                  ! 4       4      tL]J! ]<P                  4       4      tM]LtN. ]<O]NO5tO]7tP]8tQRtR]R U UUu/ uF  w  rp]2V,          VbK  	  uppp tS]J;QJ d    . R  ]R 4       F  NK  	  5M! R  ]R 4       4      tT ! R! R"]U4      tV ! R# R$]V4      tW ! R% R&]V4      tX ! R' R(]V4      tY]! R)R)R*7       ! R+ R,4      4       tZR- R. lt[R/ R0 lt\R1 R2 lt]R3 R4 lt^RR5 R6 llt_R7 R8 lt`R9 R: ltaRR; R< lltbR= R> ltcR? R@ ltdRA RB lteRC RD ltfRE RF ltgRG RH lthRI RJ ltiRK RL ltj]! R)R)R*7       ! RM RN4      4       tk]P                  ! RO4      tlRPRQRRRQRSRTRURTRVRWRXRW/tmRY RZ ltnR[ R\ ltoR] R^ ltpR_ R` ltqRa Rb ltrRc Rd ltsRe Rf lttRg Rh ltuRi Rj ltvRk Rl ltwRm Rn ltxRo Rp lty]! R)R)R*7       ! Rq Rr4      4       tz]! R)R)R*7       ! Rs Rt4      4       t{Ru Rv lt|Rw Rx lt}Ry Rz lt~R{ R| ltRR} R~ lltRR R lltRR R lltRR R lltR R ltRR R lltRR R lltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R lt]R R l4       tR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R lt]R8X  d8   ]EPF                  EPI                  RR4       ]! ]! ]EPL                  4      4      hR# u uppp i )    )annotationsN)Iterator)contextmanager)	dataclass)Path)AnyLiteral)AccountLockErrorAccountUseAuthorizationHumanOverrideErrorauthorize_account_userevalidate_account_use)AccountRegistryAuthorityBindingAuthorityMode)AuthorityConfigurationErrorbuild_authority_launchresolve_authority_data_plane)ClaudeAdapterCodexAdapterCommandRouteraccount_spend_cap_block)MODEL_ALIASES)AllAccountsCappedError)runtime_dirzgpt-5.6-solzgpt-5.6-lunaCLAUDEX_PROXY_SCOPEzclaudex-proxy.slicez--dangerously-skip-permissionsfablezclaude-fable-5opuszclaude-opus-5sonnetzclaude-sonnet-5zcunsupported-security-boundary: remote seats accept only GPT-backed models (sol, terra, luna, gpt-*)z ^gpt-[A-Za-z0-9][A-Za-z0-9._-]*$z^claude-z#.local/state/overdeck/seat-bindingsi    z [\x00-\x08\x0b\x0c\x0e-\x1f\x7f]c              #  L   "   T F  w  p pR F  pRV RV 2x  K  	  K  	  R# 5i) ANTHROPIC_DEFAULT__MODELN)r!   _NAME_DESCRIPTION_SUPPORTED_CAPABILITIES ).0slot_suffixs   &   Q/home/user/overdeck-private-tests/workstation-ai-broad/modules/systray/claudex.py	<genexpr>r-      s7      (
aJ fVH-J .(s   "$c                      ] tR t^t^tRtR# )ClaudexErrorr'   N__name__
__module____qualname____firstlineno__	exit_code__static_attributes__r'       r,   r/   r/      s    Ir7   r/   c                      ] tR t^t^tRtR# )MissingBinaryErrorr'   Nr0   r'   r7   r,   r9   r9      s    Ir7   r9   c                      ] tR t^tRtR# )CredentialConflictErrorr'   N)r1   r2   r3   r4   r6   r'   r7   r,   r;   r;      s    r7   r;   c                  B   a  ] tR t^t^KtRR V 3R llltR R ltRtV ;t# )ClaudexCappedErrorc               $    V ^8  d   QhRRRRRR/# )   	resume_at
str | NonetoolstrreturnNoner'   )formats   "r,   __annotate__ClaudexCappedError.__annotate__   s!     # #* #C #d #r7   c                	:   < \         SV `  R V R24       Wn        R# )zclaudex: selected z account is spend-cappedN)super__init__r@   )selfr@   rB   	__class__s   &&&r,   rK   ClaudexCappedError.__init__   s     -dV3KLM"r7   c                   V ^8  d   QhRR/# r?   rD   rC   r'   )rF   s   "r,   rG   rH      s     : :c :r7   c                	|    R RRRRR/pV P                   e   V P                   VR&   \        P                  ! VRR7      # )	okFdetailzrate-limitedreasonzall-accounts-cappedr@   
separators,:)r@   jsondumps)rL   payloads   & r,   refusal_jsonClaudexCappedError.refusal_json   sD    %n+&

 >>%#'>>GK zz'j99r7   )r@   )Codex)	r1   r2   r3   r4   r5   rK   r]   r6   __classcell__)rM   s   @r,   r=   r=      s    I# #: :r7   r=   T)frozenslotsc                  `    ] tR t^t$ R]R&   R]R&   R]R&   RtR]R&   RtR	]R
&   RtR]R&   RtR# )SelectedAccountrC   slugr   native_auth_pathproxy_config_dirNPath | Nonebase_dirAccountUseAuthorization | NoneauthorizationAuthorityBinding | Noneauthority_bindingr'   )	r1   r2   r3   r4   __annotations__ri   rk   rm   r6   r'   r7   r,   rd   rd      s4    
I Hk 48M1815.5r7   rd   c                   V ^8  d   QhRR/# )r?   rD   ztuple[Path, Path]r'   )rF   s   "r,   rG   rG      s     6 6+ 6r7   c                 N    \        4       \        P                  ! 4       R ,          3# )z.codex-tray)r   r   homer'   r7   r,   _codex_tray_dirsrr      s    =$))+555r7   c                    V ^8  d   QhRRRR/# )r?   tokenrC   rD   ztuple[str, ...]r'   )rF   s   "r,   rG   rG      s      S _ r7   c                     \        4       P                  V 4      pVe   W8X  d   V 3# W3#   \        \        \        3 d    R p L*i ; iN)r   resolve_profile_tokenOSError
ValueErrorKeyError)rt   resolveds   & r,   _codex_account_candidatesr|      sT    "$::5A 8,x	 Z* s   + AAc               $    V ^8  d   QhRRRRRR/# )r?   ri   r   re   rC   rD   zSelectedAccount | Noner'   )rF   s   "r,   rG   rG      s"      $ c 6L r7   c                   V R ,          V,          R,          R,          pRp \        V R7      P                  V4      pVeJ   VP                  \        P                  8X  d+   \        WVP                  P                  R,          V VR7      # VP                  4       '       d+   \        WVP                  P                  R,          V VR7      # R#   \        \        \        \
        P                  3 d    Rp Li ; i)accounts
CODEX_HOME	auth.jsonN)ri   CLAUDEX_HOME)rm   )r   authority_binding_forrz   rx   ry   rZ   JSONDecodeErrormoder   	SUBROUTERrd   parentis_file)ri   re   	auth_pathbindings   &&  r,   _selected_candidater      s    :%,|;kII'+G!84JJ4P w||}/F/FFY--44~Ex%
 	
 Y--44~Ex%
 	
  gz4+?+?@ s   C 'C65C6c                    V ^8  d   QhRRRR/# )r?   selectedrd   rD   boolr'   )rF   s   "r,   rG   rG      s     K K/ Kd Kr7   c                l    V P                   pVR J;'       d    VP                  \        P                  8H  # rv   )rm   r   r   r   )r   r   s   & r,   _authority_selectedr      s/    ((G$JJ7<<=3J3J#JJr7   c               $    V ^8  d   QhRRRRRR/# )r?   re   rC   	tray_dirsztuple[Path, ...] | NonerD   rd   r'   )rF   s   "r,   rG   rG      s)     	O 	O
	O1	O	Or7   c                    Vf   \        4       MTp\        V 4       F!  pV F  p\        WC4      pVf   K  Vu u # 	  K#  	  \        RV : 24      h)Nz+claudex: no Systray AI Codex account named )rr   r|   r   r/   )re   r   candidate_dirs	candidateri   r   s   &&    r,   _requested_codex_accountr      sW     ,5+<%')N.t4	&H*8?H# ' 5
 DTHM
NNr7   c                    V ^8  d   QhRRRR/# )r?   re   rC   rD   rE   r'   )rF   s   "r,   rG   rG      s     4 4 4 4r7   c                `    \        \        4       V 4      pVe   \        VP                  4      hR # rv   )r   r   r=   r@   )re   blockeds   & r,   _require_codex_spend_headroomr      s,    %lnd;G !2!233 r7   c                    V ^8  d   QhRRRR/# )r?   requested_slugrA   rD   rE   r'   )rF   s   "r,   rG   rG      s     	
 	
j 	
T 	
r7   c                    V f   \        R4      h\        ;QJ d#    . R V P                  R4       4       F  NK  	  5M! R V P                  R4       4       4      p\        V4      ^8w  d   \        R4      hR # )N4--human-override-lock requires an explicit --accountc              3  p   "   T F,  qP                  4       '       g   K  VP                  4       x  K.  	  R # 5irv   )strip)r(   parts   & r,   r-   4_validate_human_override_selector.<locals>.<genexpr>   s"     U+D4

,$**,,+Ds   66rX   zH--human-override-lock requires exactly one explicit account per provider)r   tuplesplitlen)r   partss   & r,   !_validate_human_override_selectorr      sn     B
 	
 EU>+?+?+DUEEU>+?+?+DUUE
5zQ V
 	
 r7   c               $    V ^8  d   QhRRRRRR/# )r?   r   rA   human_override_lockr   rD   rd   r'   )rF   s   "r,   rG   rG     s&     > >>> >r7   c                   V'       d   \        V 4       \        4       pV^ ,          pV e   \        W4      p\        VP                  4       VP
                  f   V# \        VRVP                  VRR7      p\        VP                  VP                  VP                  VVVP                  4      # . p\        V4       Fx  w  rxVR,          p	 V	P                  RR7      P                  4       p
V	P                  4       P                  pT
'       d   \#        Y4      MRpTf   Kd  TP%                  Y) T34       Kz  	  V'       g   \'        R4      h\)        VR	 R
7      w   rVP                  p
VP                  pVP
                  pVf   Q h\        V
4       \        VRV
VRR7      pVP*                  P*                  p\        V
VVR,          VVVP                  4      #   \          d     EK+  i ; i)r   NcodexTallow_lockedexplicit_accountdefault_slugutf-8encodingz2claudex: no valid Systray AI default Codex accountc                &    V ^ ,          V ^,          3# )r   r'   )items   &r,   <lambda>*resolve_selected_account.<locals>.<lambda>/  s    tAwQ6Hr7   )keyFr   )r   rr   r   r   re   ri   r   rd   rf   rg   rm   	enumerate	read_textr   statst_mtimerx   r   appendr/   maxr   )r   r   r   lock_policy_dir	requestedrk   
candidatesindexri   default_pathre   mtimer   r*   r   account_dirs   &&              r,   resolve_selected_accountr     s    ).9 "IlO!,^G	%inn5%-NN,!
 NN&&&&''
 	
 <>J$Y/.0	))7);AACD %%'00E ;?&x6Dufh78 0 OPP)HINAq==D))I  H!$')(M ""))Kn$"" +  		s   	:GG&%G&c                    V ^8  d   QhRRRR/# )r?   rt   rC   rD   intr'   )rF   s   "r,   rG   rG   G  s     
 
s 
s 
r7   c                    V P                  R 4      ^,          pR\        V4      ) ^,          ,          p\        P                  ! \        P
                  ! W,           4      4      pVR,          p\        T\        4      '       d   T^ 8:  d   \        R4      hTR,          #   \        \        \        \        \        P                  3 d   p\        R4      ThRp?ii ; i).=expz/claudex: Codex access token has no valid expiryN  )r   r   rZ   loadsbase64urlsafe_b64decode
IndexErrorrz   	TypeErrorry   r   r/   
isinstancer   )rt   segmentpaddingr\   r   excs   &     r,   _jwt_exp_msr   G  s    W++c"1%#g,*+**V55g6GHIen c33!8LMM:	 )Z9M9MN WLMSVVWs   A+B *CCCc               $    V ^8  d   QhRRRRRR/# )r?   valueobjectfieldrC   rD   r'   )rF   s   "r,   rG   rG   T  s!      F 3 3 r7   c                |    \        V \        4      '       d   V P                  4       '       g   \        R V R24      hV # )z)claudex: missing Codex credential field '')r   rC   r   r/   )r   r   s   &&r,   _required_stringr   T  s3    eS!!FugQOPPLr7   c                    V ^8  d   QhRRRR/# )r?   nativedict[str, object]rD   r'   )rF   s   "r,   rG   rG   Z  s      !2 7H r7   c                .   V P                  R 4      p\        V\        4      '       g   \        R4      h\	        VP                  R4      R4      p\	        VP                  R4      R4      p\	        VP                  R4      R4      pRVR	VR
\        V4      RV/# )tokens)claudex: invalid native Codex auth formataccess_tokenztokens.access_tokenrefresh_tokenztokens.refresh_token
account_idztokens.account_idaccessrefreshexpires	accountId)getr   dictr/   r   r   )r   r   r   r   r   s   &    r,   native_to_proxy_authr   Z  s    ZZ!Ffd##FGGfjj8:OPFvzz/:<RSG!&**\":<OPJ&7;v&Z	 r7   c                    V ^8  d   QhRRRR/# )r?   pathr   rD   dict[str, Any]r'   )rF   s   "r,   rG   rG   i  s      D ^ r7   c                     \         P                  ! V P                  R R7      4      p\        T\        4      '       g   \        RT  24      hT#   \        \         P                  3 d   p\        RT  24      ThRp?ii ; i)r   r   z"claudex: invalid credential file: N)rZ   r   r   rx   r   r/   r   r   )r   r\   r   s   &  r,   _read_json_objectr   i  s|    Q**T^^W^=> gt$$?vFGGN	 T))* Q?vFGSPQs   &A A=)A88A=c               $    V ^8  d   QhRRRRRR/# )r?   r   r   r\   r   rD   rE   r'   )rF   s   "r,   rG   rG   s  s"     
  
 T 
 ,= 
 $ 
 r7   c                   V P                   P                  R R RR7       \        P                  ! V P                   R4       \        P
                  ! RRV P                   RR7      ;_uu_ 4       p\        P                  ! WRR7       VP                  R4       \        VP                  4      pR	R	R	4       \        P                  ! XR
4       \        P                  ! W04       R	#   + '       g   i     L?; i)T  parentsexist_okr   wr   F)r   dirdeleterU   
Ni  rW   )r   mkdiroschmodtempfileNamedTemporaryFilerZ   dumpwriter   namereplace)r   r\   handle	temp_paths   &&  r,   _atomic_write_jsonr  s  s    KKdT>HHT[[% 		$	$g4;;u
 
			'j9T%	
 HHYJJy
 
s   ,?C""C2	c               (    V ^8  d   QhRRRRRRRR/# )r?   native_pathr   r   r   proxyrD   rE   r'   )rF   s   "r,   rG   rG     s0     , ,,, , 
	,r7   c                   VP                  R 4      p\        V\        4      '       g   \        R4      h\	        VP                  R4      R4      VR&   \	        VP                  R4      R4      VR&   \	        VP                  R4      R4      VR&   \
        P                  ! R\
        P                  ! 4       4      VR	&   \        W4       R
# )r   r   r   r   r   r   r   r   z%Y-%m-%dT%H:%M:%SZlast_refreshN)	r   r   r   r/   r   timestrftimegmtimer  )r
  r   r  r   s   &&& r,   _export_proxy_to_nativer    s    
 ZZ!Ffd##FGG-eii.A8LF>.uyy/CYOF?+EIIk,BKPF<!]]+?OF>{+r7   c               $    V ^8  d   QhRRRRRR/# )r?   r
  r   
proxy_pathrD   rE   r'   )rF   s   "r,   rG   rG     s!     5 5t 5 5$ 5r7   c                   \        V 4      p\        V4      pVP                  4       '       g   \        W4       R # \        V4      p\	        VP                  R4      R4      p\	        VP                  R4      R4      p\	        VP                  R4      R4      pWsR,          8w  d   \        R4      hVR,          p\        V\        4      '       g   \        R4      hTp	\        V4      p
\        VR,          4      pW8w  d   W8X  d   \        R4      hW8  d   \        WV4       R # W8  g   WSR,          8w  d   \        W4       R # R # )Nr   r   r   z4claudex: proxy credential belongs to another accountr   z*claudex: invalid native Codex token expiryzTclaudex: divergent Codex refresh tokens; re-authenticate selected Systray AI account)r   r   existsr  r   r   r;   r   r   r/   r   rC   r  )r
  r  r   native_proxyr  proxy_accessproxy_refreshproxy_accountnative_exp_value
native_exp	proxy_expnative_refreshs   &&          r,   reconcile_credentialsr    s   {+F'/L:4j)E#EIIh$7BL$UYYy%99EM$UYY{%;[IM[11%&\]]#I.&,,GHH!JL)Ii01N&:+B%b
 	
 U;		<3I#I:4 $Jr7   c                   V ^8  d   QhRR/# )r?   rD   r   r'   )rF   s   "r,   rG   rG     s     , ,S ,r7   c                    \         P                   ! \         P                  \         P                  4      ;_uu_ 4       p V P                  R4       \	        V P                  4       ^,          4      uuRRR4       #   + '       g   i     R# ; i)	127.0.0.1N)r!  r   )socketAF_INETSOCK_STREAMbindr   getsockname)servers    r,   find_available_portr(    sQ    	v~~v'9'9	:	:f$%6%%'*+ 
;	:	:	:s   1A88B		c                  :    ] tR tRt$ R]R&   R]R&   RtR]R&   RtR	# )
AccountOverridesi  rA   r   claudeFr   r   r'   N)r1   r2   r3   r4   rn   r   r6   r'   r7   r,   r*  r*    s     %%r7   r*  z[0-9a-fA-F-]{8,}	--accountbothz	--profilez--codex-accountr   z--codex-profilez--claude-accountr+  z--claude-profilec                    V ^8  d   QhRRRR/# r?   argv	list[str]rD   z"tuple[AccountOverrides, list[str]]r'   )rF   s   "r,   rG   rG     s     !  ! ) ! 0R ! r7   c                   / p. p^ pRpV\        V 4      8  d   W,          pVR8X  d   RpV^,          pK,  VP                  R4      '       d   \        R4      hVP                  R4      w  rgp\        P                  V4      p	V	f   VP                  V4       V^,          pK  V'       d   WV	&   V^,          pK  VP                  R4      '       g   V^,           \        V 4      8  d   \        RV R24      hW^,           ,          W&   V^,          pEK  VP                  R	4      p
\        VP                  R
V
4      VP                  RV
4      V4      pW3# )r   Fz--human-override-lockTz--human-override-lock=z4claudex: --human-override-lock does not take a valuer   	claudex: z requires an accountr-  r   r+  )	r   
startswithr/   	partitionACCOUNT_FLAGSr   r   endswithr*  )r0  chosen	forwardedr   r   argumentflagr*   inlineproviderr-  	overridess   &           r,   parse_account_overridesr?    sL   FIE
#d)
;.."&QJE788UVV",,S1 $$T*X&QJE%8QJES!!UQY#d)%;4&0DEFF	?
::fD 

7D!

8T"I
 r7   c                    V ^8  d   QhRRRR/# r/  r'   )rF   s   "r,   rG   rG     s     > >y >5W >r7   c                |    R V 9  d   \        V 4      # V P                  R 4      p\        V RV 4      w  r#V. VOWR O3# )--N)r?  r   )r0  separator_indexr   wrapper_argvs   &   r,   parse_seat_account_overridesrE    sT    4&t,,jj&O4T:J?5KLH=|=d+;&<===r7   c                    V ^8  d   QhRRRR/# r?   rt   rC   rD   r'   )rF   s   "r,   rG   rG     s     
 
s 
s 
r7   c                $  a  / \         C\        CpVP                  S 4      pVe   V# S '       db   \        ;QJ d    V 3R lR 4       F  '       g   K   RM	  RM! V 3R lR 4       4      '       g"   \	        RS  RRP                  V4       R24      hS # )	Nc              3  ,   <"   T F	  qS9   x  K  	  R # 5irv   r'   )r(   	separatorrt   s   & r,   r-   .resolve_claudex_model_token.<locals>.<genexpr>  s     M_	e+_   TFzclaudex: unknown model alias 'z' (valid aliases: z, )-r   /)r   NATIVE_MODEL_ALIASESr   anyr/   join)rt   aliasesr{   s   f  r,   resolve_claudex_model_tokenrU    s    77"67G{{5!HSSM_MSSSM_MMM,UG 4#yy12!5
 	
 Lr7   c                    V ^8  d   QhRRRR/# )r?   r0  r1  rD   ztuple[str | None, list[str]]r'   )rF   s   "r,   rG   rG     s      i $@ r7   c                P   R p. p^ p0 \         m\        mpV\        V 4      8  Ed    W,          pVR9   d)   V^,           \        V 4      8  d   ^W^,           ,          rvMeVP                  R4      '       g   VP                  R4      '       d   ^VP	                  R^4      ^,          rvMVP                  V4       V^,          pK  \        V4      pW9   d   TpMDVP                  R4      '       d   VP                  RV.4       MVP                  WW6,            4       W6,          pEK  W3# )N-m--model-m=--model=r      rX  rY  )AVAILABLE_MODELSNATIVE_PICKER_MODELSr   r4  r   r   rU  extend)	r0  modelr9  r   known_modelsr:  widthrt   r{   s	   &        r,   parse_modelrc    s
   EIE=%=(<=L
#d)
;((UQYT-Bd19o5  ''8+>+>z+J+JhnnS!4Q75X&QJE.u5#E  &&i23T%-89r7   c                   V ^8  d   QhRR/# )r?   rD   dict[str, str]r'   )rF   s   "r,   rG   rG     s     	 	. 	r7   c                 |    / p \          F/  w  rp\        V,          pW@R V R2&   W0R V R2&   V R2V R V R2&   K1  	  V # )r"   r#   _MODEL_NAMEz through claude-code-proxy_MODEL_DESCRIPTION)PROXY_PICKER_SLOTSr   )pickerr)   aliaslabelr`  s        r,   proxy_picker_envrm    sk    F0Ue$49#D6019>#D656g/0 	#D6);<=	 1 Mr7   c                    V ^8  d   QhRRRR/# )r?   r0  r1  rD   r'   )rF   s   "r,   rG   rG   %  s     / /i /I /r7   c                .    \         V 9   d   V # \         .V O# rv   )DANGEROUS_PERMISSIONS_FLAGr0  s   &r,   default_claude_argsrr  %  s    !T)&...r7   c               $    V ^8  d   QhRRRRRR/# )r?   r0  r1  settings_pathr   rD   r'   )rF   s   "r,   rG   rG   +  s&     B Bi B B Br7   c                >    V ^ ,          R\        V4      .V R,          O# )r   
--settings   NN)rC   )r0  rt  s   &&r,   model_settings_argsry  +  s!    G\3}#5ARAAr7   c                   V ^8  d   QhRR/# )r?   rD   rE   r'   )rF   s   "r,   rG   rG   /  s     # #4 #r7   c                    \         P                  P                  \        4      R 8X  d   R# \        P
                  ! R4      p V f   \        R4      hV RRRRRR	\         2R
\         P                  ! 4        R2R\         R2\        P                  ^ ,          .
\        P                  R,          Op\         P                  ! W4       R# )1Nzsystemd-runz/claudex: required binary not found: systemd-runz--userz--scopez--quietz	--collectz
--same-dirz--slice=z--unit=claudex-proxy-z.scopez	--setenv=z=1rw  )r   environr   PROXY_SCOPE_MARKERshutilwhichr9   PROXY_SLICEgetpidsysr0  execv)systemd_runcommands     r,   enter_proxy_slicer  /  s    	zz~~()S0,,}-K !RSS
;- 
		}F3
&'r* 
"G HH["r7   c                    V ^8  d   QhRRRR/# )r?   expected_parent_pidr   rD   rE   r'   )rF   s   "r,   rG   rG   E  s      # $ r7   c                N   \         P                  ! R RR7      pVP                  ^\        P                  4      ^ 8w  d6   \         P
                  ! 4       p\        V\        P                  ! V4      4      h\        P                  ! 4       V 8w  d   \        P                  ! ^4       R # R # )NT)	use_errno)ctypesCDLLprctlsignalSIGTERM	get_errnorx   r   strerrorgetppid_exit)r  libcerrors   &  r,   _set_parent_death_signalr  E  sl    ;;tt,Dzz!V^^$)  "eR[[/00	zz|**
 +r7   c               $    V ^8  d   QhRRRRRR/# )r?   processsubprocess.Popen[str]portr   rD   rE   r'   )rF   s   "r,   rG   rG   N  s"     ; ;1 ; ; ;r7   c                   \         P                  ! 4       ^
,           pRV R2p\         P                  ! 4       V8  dp   V P                  4       e   \        R4      h \        P
                  P                  VRR7      ;_uu_ 4       pVP                  ^8X  d    RRR4       R#  RRR4       K  \        R4      h  + '       g   i     K  ; i  \        \        P                  P                  3 d    \         P                  ! R4        K  i ; i)	
   http://127.0.0.1:z/healthzNz&claudex: proxy exited before readinessg      ?timeoutg?z claudex: proxy readiness timeout)r  	monotonicpollr/   urllibrequesturlopenstatusrx   r  URLErrorsleep)r  r  deadlineurlresponses   &&   r,   wait_for_proxyr  N  s    ~~"$HdV8
,C
..
X
%<<>%GHH	''T'::h??c) ;:) ;:
 9
:: ;:: ../ 	JJt	s6   )C B7C "C 7C	C C ;D
	D
c                    V ^8  d   QhRRRR/# )r?   r  rC   rD   r'   )rF   s   "r,   rG   rG   ]  s      # # r7   c                   \         P                  ! 4       R ,          R,          V ,          pVP                  4       '       dV   \        P                  ! V\        P
                  4      '       d+   VP                  4       P                  R8X  d   \        V4      # \        P                  ! V 4      pVf   \        RV  24      hV# ).claudebinz_tmpjail-shim.shz$claudex: required binary not found: )r   rq   r   r   r   X_OKresolver  rC   r  r  r9   )r  shimr   s   &  r,   _require_binaryr  ]  s     99;"U*T1D||~~"))D"''22<<>"44t9<<D| #Gv!NOOKr7   c                    V ^8  d   QhRRRR/# )r?   r  r  rD   rE   r'   )rF   s   "r,   rG   rG   k  s        -  $  r7   c                    V P                  4       e   R # V P                  4         V P                  ^R7       R #   \        P                   d'    T P                  4        T P                  ^R7        R # i ; i)Nr  )r  	terminatewait
subprocessTimeoutExpiredkill)r  s   &r,   
_terminater  k  s\    ||~! Q$$  Q s   : 7A54A5c                  n    ] tR tRt$ R]R&   R]R&   R]R&   RtR	]R
&   RtR]R&   RtR]R&   RtR	]R&   Rt	R# )ClaudeAccountiv  rC   re   r   rq   re  envNrh   ri   rj   rk   rl   rm   settings_homer'   )
r1   r2   r3   r4   rn   ri   rk   rm   r  r6   r'   r7   r,   r  r  v  s=    
I
J	 Hk 48M1815.5!%M;%r7   r  c                  ,    ] tR tRt$ R]R&   R]R&   RtR# )SeatWrapperModeli  rC   r`  r1  r0  r'   N)r1   r2   r3   r4   rn   r6   r'   r7   r,   r  r    s    J
Or7   r  c                    V ^8  d   QhRRRR/# )r?   re   rC   rD   r   r'   )rF   s   "r,   rG   rG     s        r7   c                   \        \        4       4      pVP                  P                  4        FV  pVP                  P	                  W 4      pVf   K$  VP                  P                  W#4      P                  4       '       g   KU   R# 	  R# )NTF)r   r   adaptercandidate_tray_dirsrw   account_homer  )re   routercandidate_dirresolved_slugs   &   r,   claude_account_existsr    sh    =?+F;;=<<]Q >>&&}DKKMM > r7   c                    V ^8  d   QhRRRR/# )r?   r   r*  rD   rA   r'   )rF   s   "r,   rG   rG     s      "2 z r7   c                    V P                   e   V P                  f   R # V P                   V P                  8w  d   R # V P                   # rv   )r   r+  )r   s   &r,   pinned_account_slugr    s5    ~~!8~~(>>r7   c                    V ^8  d   QhRRRR/# )r?   r   r*  rD   r   r'   )rF   s   "r,   rG   rG     s     + +7G +D +r7   c                D    \        V 4      pVf   R# \        V4      '       * # NF)r  r  )r   re   s   & r,   (should_run_codex_only_for_pinned_accountr    s"    x(D|$T***r7   c                    V ^8  d   QhRRRR/# )r?   r  r   rD   r   r'   )rF   s   "r,   rG   rG     s     ! !d !s !r7   c                    ^ RI Hp V! V 4      # )r   )resolve_credentials)claude_credentialsr  )r  r  s   & r,   r  r    s    A<  r7   c               $    V ^8  d   QhRRRRRR/# )r?   r   rA   r   r   rD   r  r'   )rF   s   "r,   rG   rG     s+     F FFF Fr7   c           	        V'       d   \        V 4       \        \        4       4      pV'       d   VP                  V V R J RR7      pMVP                  W R J R7      pVf   V e   \	        RV : 24      h\	        R4      h\        V\        4      '       d   \        VP                  R4      hVw  rEpVP                  P                  4       p\        VRVVV R JR7      pVP                  p	V	P                  WE4      p
V
e   V
P                  MR pVEe3   VP                  \        P                   8X  Ed   VP"                  '       d   \	        R	4      h \%        WJR. \&        P(                  R
7      pTP,                  P.                  R8w  d#   \	        RTP,                  P0                   24      hTP2                  R,          pTP5                  RRRR7       \&        P6                  ! TR4       \9        TP:                  4      p\=        T4      TR&   Y_R&   TP?                  RR 4       \A        Yx4       \C        Y\PD                  YYT4      #  V	PG                  V4      ;'       g    . pV F!  p\M        RV 2\N        PP                  R7       K#  	  \A        Wx4       \9        V	PS                  V4      4      p\=        \U        V4      PV                  P2                  4      VR&   \C        WVWWV4      #   \*         d   p\	        RT 24      ThR p?ii ; i  \H        \J        3 d+   p. p\M        RT 2\N        PP                  R7        R p?LR p?ii ; i)NT)notify_fallbackignore_locks)r  z,claudex: no Systray AI Claude account named z3claudex: no valid Systray AI default Claude accountClauder+  r   "claudex: Gateway: migration paused)inherited_environmentr3  readyr   r   r   CLAUDE_CONFIG_DIRSYSTRAY_CLAUDE_ACCOUNT_SLUGSYSTRAY_CLAUDE_ACCOUNT_HOMEz$claudex: shared state sync skipped: filez"claudex: kept per-account copy of CLAUDE_SECURESTORAGE_CONFIG_DIR),r   r   r   _resolve_accountr/   r   r   r=   r@   r  r   r   accountrm   r   r   r   quiescedr   r   r}  r   sanitized_statusstaterS   r   r   r   r   environmentrC   popr   r  gateway_homesync_before_execrx   RuntimeErrorprintr  stderr	build_envr  r   )r   r   r  r{   ri   re   r  r   rk   r  account_recordr   launchr   r  r  	conflictsconflicts   &&                r,   resolve_claude_accountr    s    ).9=?+F***d2 + 
 **d,B + 
 %!MnM_`aaPQQ(233 !3!3X>>#+ HLnn446O)('t3M nnG__X4N2@2Ln..RVGw||}/F/FFCDD	;+(BbjjF
 ""((G36+B+B+I+I*JKLL$++n<D4eD
&6%%&#&}#5 -1)*-t4>%%s]Ub
 	
M,,X6<<"	 28*=CJJO ?:
w  .
/C-01D\1R1W1W1^1^-_C)*C-, 5 + 	;3%01s:	;$ \" M	4SE:LLMs6   K   L L  K?+K::K?L= L88L=c                    V ^8  d   QhRRRR/# )r?   r   rA   rD   rC   r'   )rF   s   "r,   rG   rG     s     7 7
 7c 7r7   c                ,    \        V 4      P                  # rv   )r  re   )r   s   &r,   resolve_claude_account_slugr    s    !.1666r7   c                    V ^8  d   QhRRRR/# )r?   r   rA   rD   r'   )rF   s   "r,   rG   rG     s       z r7   c                   \        \        4       4      pVP                  pV eZ   VP                  4        FC  pVP	                  W04      pVf   K  VP                  W44      P                  4       '       g   KA  Vu # 	  R # VP                  VP                  4       4      pVf   R # VP                  VP                  VP                  4      P                  4       '       d   VP                  # R # rv   )
r   r   r  r  rw   r  r  selected_defaultri   re   )r   r  r  r  r  r  s   &     r,   existing_claude_account_slugr    s    =?+FnnG!$88:M#99-XM$##MAHHJJ$$ ; //0K0K0MN,557G7L7LMTTVV$$$r7   c               $    V ^8  d   QhRRRRRR/# )r?   account_slugrC   rq   rh   rD   r   r'   )rF   s   "r,   rG   rG     s!     < <C <{ <d <r7   c                f    Vf   \         P                  ! 4       MTpV\        ,          V  R2,          # )Nz.json)r   rq   SEAT_BINDING_REL)r  rq   roots   && r,   seat_binding_pathr    s+    ,499;DD""~U%;;;r7   c                   V ^8  d   QhRR/# )r?   rD   z
int | Noner'   )rF   s   "r,   rG   rG     s     	 	* 	r7   c                 8   \         P                  p \        \         R 4      '       d   V \         P                  ,          p \        \         R4      '       d   V \         P                  ,          p \        \         R4      '       g   R# V \         P
                  ,          p V # )	O_CLOEXEC
O_NONBLOCK
O_NOFOLLOWN)r   O_RDONLYhasattrr  r  r  )flagss    r,   _seat_binding_open_flagsr    sd    KKEr;r<  2|$$	R]]ELr7   c               $    V ^8  d   QhRRRRRR/# )r?   r  rC   rq   rh   rD   z-dict[str, object] | Literal['invalid'] | Noner'   )rF   s   "r,   rG   rG     s$     5 55(525r7   c                   \        W4      p\        4       pVf   R# RpRp \        P                  ! \	        V4      V4      p \        P
                  ! V4      p\        P                  ! TP                  4      '       d$    T^ 8  d    \        P                  ! T4       R# R# \        P                  ! TP                  4      '       g$    T^ 8  d    \        P                  ! T4       R# R# TP                  \        8  d$    T^ 8  d    \        P                  ! T4       R# R#  \        P                  ! T\        ^,           4      p\        T4      \        8  d$    T^ 8  d    \        P                  ! T4       R# R#  T^ 8  d    \        P                  ! T4       M  TP'                  RRR7      p \*        P,                  ! T4      p	\1        T	\2        4      '       g   R# \4         FC  p
T	P7                  T
4      p\1        T\        4      '       d   TP9                  4       '       d   KB   R# 	  T	#   \         d7     T^ 8  d,    \        P                  ! T4       R#   \         d     R# i ; iR# i ; i  \         d     R# i ; i  \         d     R# i ; i  \         d     R# i ; i  \         d7     T^ 8  d,    \        P                  ! T4       R#   \         d     R# i ; iR# i ; i  \         d     R# i ; i  \          d7     T^ 8  d,    \        P                  ! T4       R #   \         d     R # i ; iR # \         d   pTP"                  \"        P$                  8X  d9    R p?T^ 8  d,    \        P                  ! T4       R #   \         d     R # i ; iR #  R p?T^ 8  d,    \        P                  ! T4       R#   \         d     R# i ; iR# R p?ii ; i  \         d     ELQi ; i  T^ 8  d*    \        P                  ! T4       i   \         d     i i ; ii ; i  \(         d     R# i ; i  \*        P.                   d     R# i ; i)Ninvalidr7   r   strict)errors)r  r  r   openrC   fstatrx   closer   S_ISLNKst_modeS_ISREGst_sizeSEAT_BINDING_MAX_BYTESreadr   FileNotFoundErrorerrnoENOENTdecodeUnicodeDecodeErrorrZ   r   r   r   r   SEAT_BINDING_REQUIRED_FIELDSr   r   )r  rq   r   r  fdrawstr   textr\   r   r   s   &&          r,   load_seat_bindingr&    s    \0D$&E}	B
CWWSY&	"B <<

##$ 7 # ||BJJ''  7  ::.. 7 	''"4q89C s8,, 7  - 7 
zz'(z3**T" gt$$-E"%%%U[[]] . NQ  	( 7  +	0  7 7   	 7  	     7    99$ 7   7     7      s   K? H/ %K? I3 !%K? J *K? J #"J) K? "K- O  P' 2P9 /I0:K? I I*)I*/I00K? 3JJJJJ&%J&)K*4K? =K K$#K$)K**K? -K<;K<?O
O2 L+ +L:9L:?OO	O(O2 4N NN O2 ,O OOOO2  O/.O/2P$;PP$P P$P  P$'P65P69QQc               $    V ^8  d   QhRRRRRR/# )r?   r  rA   rq   rh   rD   rE   r'   )rF   s   "r,   rG   rG   P  s$      $/	r7   c                t    V f   R # \        W4      pVf   R # VR8X  d   \        R4      h\        RV : R24      h)Nr  zJclaudex: invalid seat binding record; use claudex --seat or repair bindingzclaudex: account z" is seat-bound; use claudex --seat)r&  r/   )r  rq   r   s   && r,   enforce_local_seat_binding_gater)  P  sT     3G)X
 	
 
L++MN r7   c                    V ^8  d   QhRRRR/# )r?   r0  r1  rD   ztuple[bool, list[str]]r'   )rF   s   "r,   rG   rG   a  s      ) (> r7   c                    V '       d   V ^ ,          R8w  d   RV 3# \        V 4      ^8  d*   V ^,          P                  R4      '       d   \        R4      hRV R,          3# )r   z--seatFz#claudex: unsupported seat flag formTrw  )r   r4  r/   rq  s   &r,   parse_seat_flagr,  a  sS    47h&d{
4y1}a++H55@AAb>r7   c                    V ^8  d   QhRRRR/# rG  r'   )rF   s   "r,   rG   rG   i  s     A AC AC Ar7   c                  a V P                  4       oS'       g   \        R 4      hS\        9   g   \        P	                  S4      '       d   \        \
        4      hS\        9   d   \        S,          # \        P                  S4      '       d   S# \        ;QJ d    V3R lR 4       F  '       g   K   RM	  RM! V3R lR 4       4      '       g   \        S4       \        RS 24      h) seat-remote: --model is requiredc              3  ,   <"   T F	  qS9   x  K  	  R # 5irv   r'   )r(   rJ  r#  s   & r,   r-   +resolve_seat_model_token.<locals>.<genexpr>s  s     AICrL  TFz seat-remote: unknown seat model rN  )r   r/   rQ  SEAT_NATIVE_MODEL_REmatchSEAT_UNSUPPORTED_BOUNDARYSEAT_MODEL_ALIASESSEAT_GPT_MODEL_RE	fullmatchrR  rU  )rt   r#  s   &@r,   resolve_seat_model_tokenr8  i  s    
++-C=>>
""&:&@&@&E&E455
  !#&&""3''
3AA333AAAA#C(
9#?
@@r7   c                    V ^8  d   QhRRRR/# r?   r0  r1  rD   rE   r'   )rF   s   "r,   rG   rG   x  s     	V 	Vy 	VT 	Vr7   c                  a \        V 4       F  w  po\        S\        4      '       g   \        R V 24      h\        P                  S4      '       d   \        RV 24      hS\        9   d   \        RS 24      h\        ;QJ d#    V3R l\         4       F  '       g   K   RM	  RM! V3R l\         4       4      '       g   K  \        RS 24      h	  R# )z,claudex: forwarded argv not string at index z.claudex: forwarded control character at index z(claudex: forwarded security arg denied: c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5irv   )r4  )r(   prefixr:  s   & r,   r-   /validate_seat_forwarded_argv.<locals>.<genexpr>  s!     T9Svx""6**9Ss   !TFN)	r   r   rC   r/   SEAT_CONTROL_REsearchSEAT_FORWARDED_EXACT_DENYrR  SEAT_FORWARDED_PREFIX_DENY)r0  r   r:  s   & @r,   validate_seat_forwarded_argvrC  x  s    $T?x(C((!MeWUVV!!(++!OPUwWXX00!I(TUU3T9ST333T9STTT!I(TUU +r7   c                    V ^8  d   QhRRRR/# )r?   r0  r1  rD   r  r'   )rF   s   "r,   rG   rG     s     '1 '19 '11A '1r7   c                "   . pR V 9   d#   V P                  R 4      pV RV pW^,           R pM\        V 4      pRpRp. p^ pV\        V4      8  d   W7,          pVR9   dC   V^,           \        V4      8  d   \        R4      hVe   RpW7^,           ,          pV^,          pKa  VP	                  R4      '       g   VP	                  R4      '       d+   Ve   RpVP                  R^4      ^,          pV^,          pK  VR8X  g   VP	                  R	4      '       d   \        R
4      hVP                  V4       V^,          pK  VP                  V4       V'       d   \        R4      hVf   \        R4      h\        V4      p	\        V4       \        W4      # )rB  NFr/  TrZ  r[  r   --fallback-model--fallback-model=z1claudex: --fallback-model is forbidden for --seatz-claudex: duplicate wrapper --model for --seatr\  )r   listr   r/   r4  r   r   r_  r8  rC  r  )
r0  explicit_forwardedrC  rD  r`  	duplicater9  r   r:  r{   s
   &         r,   parse_seat_wrapper_modelrK    s   $&t|**T*,_-!A"5"78DzEIIE
#l#
#&((qyC--"#EFF  	 +EQJEu%%)<)<Z)H)H  	NN3*1-EQJE))X-@-@AT-U-URSS"
'(JKK}=>>'.H +H00r7   c                    V ^8  d   QhRRRR/# r:  r'   )rF   s   "r,   rG   rG     s      I $ r7   c                   R pRV 9   g   RV 9   d   \        V4      h^ pV\        V 4      8  d   W,          pVR8X  dR   V^,           \        V 4      8  g%   W^,           ,          P                  R4      '       d   \        V4      hV^,          pKp  VR8X  d.   V^,           \        V 4      8  d   \        V4      hV^,          pK  V^,          pK  R# )zNclaudex: --seat requires an explicit session id (resume <id> or --resume <id>)z
--continuez-cresumerO  --resumeN)r/   r   r4  )r0  messager   r:  s   &   r,   validate_seat_resume_argvrQ    s    ^Gttt|7##E
#d)
;xqyCI%ai)C)CC)H)H"7++QJEz!qyCI%"7++QJE
 r7   c                   V ^8  d   QhRR/# rP   r'   )rF   s   "r,   rG   rG     s     P PC Pr7   c                 <   \         P                  ! R 4      p V e   V # \        P                  ! 4       R,          R,          R ,          pVP	                  4       '       d7   \
        P                  ! V\
        P                  4      '       d   \        V4      # \        R4      h)zseat-remoter  r  z/claudex: required binary not found: seat-remote)
r  r  r   rq   r   r   r   r  rC   r9   )r   	canonicals     r,   resolve_seat_remote_binaryrU    sn    <<&D		i'%/-?IryyBGG<<9~
N
OOr7   c                    V ^8  d   QhRRRR/# )r?   r   r*  rD   rd   r'   )rF   s   "r,   rG   rG     s     4 4.> 4? 4r7   c                    V P                   ;'       d    V P                  R JpV'       d   \        V P                  R4      # \        V P                  4      # NT)r   r   r   r   overrides   & r,   _resolve_selected_for_overridesr[    sA    ++JJd0JH'==#HNN33r7   c                    V ^8  d   QhRRRR/# )r?   r   r*  rD   r  r'   )rF   s   "r,   rG   rG     s     3 3,< 3 3r7   c                    V P                   ;'       d    V P                  R JpV'       d   \        V P                  R4      # \        V P                  4      # rX  )r   r+  r  rY  s   & r,   _resolve_claude_for_overridesr^    sA    ++KKt0KH%hoot<<!(//22r7   c                    V ^8  d   QhRRRR/# )r?   r  rd   rD   rE   r'   )rF   s   "r,   rG   rG     s     H H/ Hd Hr7   c                    V P                   e3   V P                  e#   \        V P                   V P                  4       R # R # R # rv   ri   rk   r   r  s   &r,   _revalidate_selected_accountrc    8    #(=(=(Iw//1F1FG )J#r7   c                    V ^8  d   QhRRRR/# )r?   r  r  rD   rE   r'   )rF   s   "r,   rG   rG     s     H H H$ Hr7   c                    V P                   e3   V P                  e#   \        V P                   V P                  4       R # R # R # rv   ra  rb  s   &r,   _revalidate_claude_accountrg    rd  r7   c               $    V ^8  d   QhRRRRRR/# r?   r0  r1  r   r*  rD   r   r'   )rF   s   "r,   rG   rG     s"        9  (8  S  r7   c                v   \        V 4      p\        VP                  4       \        V4      p\	        V4       \
        P                  ! 4       p\        4       pVR RRRVP                  R\        V4      RVP                  R.VP                  Op\	        V4       \        P                  ! VRR7      pVP                  # )	r  z--hostautor,  z	--projectrY  rB  F)check)rK  rQ  r0  r^  rg  r   cwdrU  re   rC   r`  r  run
returncode)r0  r   wrapperr  projectbinaryr  	completeds   &&      r,   run_seatrt    s    &t,Ggll++H5Gw'hhjG')FG 
G w'we4Ir7   c               (    V ^8  d   QhRRRRRRRR/# 	r?   r`  rC   r0  r1  r   r*  rD   r   r'   )rF   s   "r,   rG   rG     s)      c  6F 3 r7   c                "   \        V4      p\        V4       VP                  p\        \        P
                  4      p. RO\        ORNRNRNRNRN F  pVP                  VR4       K  	  VP                  VP                  4       VP                  ;'       g    TpVR,          p\        VR\        \        4      /4       \        \        V4      V4      p	\        V4       \         P"                  ! \%        R	4      R
V .V	OVRR7      p
V
P&                  # )ANTHROPIC_API_KEYANTHROPIC_DEFAULT_FABLE_MODELCLAUDE_CODE_SUBAGENT_MODELCCP_CONFIG_DIRCCP_BIND_ADDRESSCCP_CODEX_SERVICE_TIERNzclaudex-anthropic-settings.jsonavailableModelsr+  rY  Fr  rl  )rx  ANTHROPIC_BASE_URLANTHROPIC_AUTH_TOKEN)r^  rg  rq   r   r   r}  PROXY_SLOT_VARIABLESr  updater  r  r  rH  r^  ry  rr  r  rn  r  ro  )r`  r0  r   r  r  
native_envvariablesettings_rootrt  native_argvresults   &&&        r,   
run_nativer    s   +H5Gw'<<Lbjj!J
 
	

 	(
 	%
 	
 	
 	!
 	x&
 gkk"))99\M!$EEM}'8$?S:T&UV%&9$&?OKw'^^		"IuC{CF
 r7   c                    V ^8  d   QhRRRR/# )r?   r   rd   rD   zIterator[int]r'   )rF   s   "r,   rG   rG      s"     UN UN/ UNm UNr7   c              #    a"   \        V 4       \        4        \        R 4      p\        4       p\        P
                  ! 4       o\        V 4      '       Ed   V P                  pVe   V P                  f   \        R4      hVP                  '       d   \        R4      h \        V P                  V4      pTP                  P                  R8w  d#   \        RTP                  P                   24      h\         P"                  ! RR7      ;_uu_ 4       p\%        T4      p\        P&                  ! TR4       TR	,          R
,          p\)        TRTP*                  RRRTP,                  /4       / \        P.                  CR\1        T4      RRRTP2                  RRR\1        T4      /Cp	TR,          p
T
P5                  RRR7      ;_uu_ 4       p\        T 4       \6        P8                  ! TRR.T	\6        P:                  TTRT3R lR7      p \=        Y4       Tx  \?        T4        RRR4       RRR4       R# V P@                  R	,          R
,          p\C        V PD                  V4       / \        P.                  CR\1        V P@                  4      RRRRR\1        V4      /Cp	V P@                  R,          p
V
PF                  PI                  RRRR7       V
P5                  RRR7      ;_uu_ 4       p\        V 4       \6        P8                  ! VRR.V	\6        P:                  VVRV3R  lR7      p \=        W4       Vx  \?        V4       \C        V PD                  V4        RRR4       R#   \         d   p\        RT 24      ThRp?ii ; i  \?        T4       i ; i  + '       g   i     EL{; i  + '       g   i     R# ; i  \?        T4       \C        T PD                  T4       i ; i  + '       g   i     R# ; i5i)!zclaude-code-proxyNz$claudex: Gateway: migration requiredr  r3  r  zclaudex-authority-)r=  r   r   r   r   r   r!   r   r{  r|  r!  CCP_CODEX_BASE_URLr}  fastPORTz	proxy.logar   r   servez--no-monitorTc                    < \        S 4      # rv   r  
parent_pids   r,   r   codex_proxy.<locals>.<lambda>Q  s    '?
'Kr7   )r  stdinstdoutr  r%  
preexec_fnr   c                    < \        S 4      # rv   r  r  s   r,   r   r  n  s    7
Cr7   )%rc  r  r  r(  r   r  r   rm   ri   r/   r  r   r   r  r  rS   r   TemporaryDirectoryr   r   r  	proxy_keygrant_expires_at_msr}  rC   responses_urlr  r  PopenDEVNULLr  r  rg   r  rf   r   r   )r   proxy_binaryr  r   
data_planer   	temporary
config_dirr   	proxy_envlog_path	proxy_logr  proxy_auth_pathr  s   &             @r,   codex_proxyr    st     *"#67L DJ8$$,,?h//7EFFCDD	;5h6G6GQJ &&,,7:+F+F+M+M*NOPP((0DEEiJHHZ'"W,{:Ij22rz==** #j/"K$j&>&>(&D	I "K/HsW55,X6"((!7N;!$,,$$K&"5/Ju% 6+ FJ 	//'9KGO(33_E
**#h778K &D	I ((;6HOO$EB	sW	-	-$X.  7N3$$C
	N5'Ju!(";";_M! 
.	-m + 	;3%01s:	;P u% 655+ FEJ 	8 u!(";";_M! 
.	-	-s   BO3O3M 2AO3B7N%>N	NN	N%'B>O3%>O$N93!O
O3M>*M99M>>O3NN	N"	N%%N6	0	O39#OOO0	*	O3c               (    V ^8  d   QhRRRRRRRR/# )	r?   r   rd   r`  rC   r  r   rD   re  r'   )rF   s   "r,   rG   rG   x  s(       s # . r7   c           
        \        \        P                  4      pVP                  R R4       . \        ORNRNRNRN F  pVP                  VR4       K  	  VP                  RRV 2RR	R
VR\        /\        4       C\        V 4      C4       V# )rx  Nry  rz  (CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC*CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYr  r  r  unusedANTHROPIC_MODELANTHROPIC_SMALL_FAST_MODEL)	r   r   r}  r  r  r  SMALL_MODELrm  _shared_claude_env)r   r`  r  
claude_envr  s   &&&  r,   proxy_claude_envr  x  s    bjj!JNN&-	' 	% 	3	
 	5 	x&  1$85$k	
 
 X
&  r7   c               (    V ^8  d   QhRRRRRRRR/# )	r?   r   rd   r  r  base_urlrC   rD   re  r'   )rF   s   "r,   rG   rG     s,      (5ADr7   c                    \        \        P                  4      pR R.\        ORNRNRN F  pVP	                  VR4       K  	  VP                  / VP                  CRVRRR	\        R
\        /C\        V 4      C4       V# )rx  r  ry  rz  r  Nr  r  r|  r  r  )
r   r   r}  r  r  r  r  HYBRID_MODELHYBRID_SMALL_MODELr  )r   r  r  r  r  s   &&&  r,   hybrid_claude_envr    s     bjj!J 
 	(	
 	% 	3 	x&  
++h4c<$&8 X
&  r7   c                   V ^8  d   QhRR/# )r?   rD   zlist[tuple[str, str]]r'   )rF   s   "r,   rG   rG     s     G G 5 Gr7   c                     \         P                  4        U u. uF  q ^ ,          \        8w  g   K  V NK  	  pp . VO\        \         \        ,          3N# u up i )zDCodex catalog entries; entries after the session model never render.)CODEX_MODEL_LABELSitemsr  )r   otherss     r,   gateway_catalog_modelsr    sM    1779U9t!W=Tdd9FUFVFl$6|$DEFF Vs
   AAc               $    V ^8  d   QhRRRRRR/# )r?   r  r   r  rC   rD   rE   r'   )rF   s   "r,   rG   rG     s!      t s t r7   c                    \        V R ,          R,          RTR\        \        P                  ! 4       R,          4      R\        4        UUu. uF  w  r#RVRV/NK  	  upp/4       R# u uppi )	cachezgateway-models.jsonbaseUrl	fetchedAtr   modelsiddisplay_nameN)r  r   r  r  )r  r  r`  rl  s   &&  r,   write_gateway_modelsr    sh    w!66xTYY[4/0$:$<$<LE une4$<	


s   
A&c                    V ^8  d   QhRRRR/# )r?   r   rd   rD   re  r'   )rF   s   "r,   rG   rG     s     
 
 
^ 
r7   c           
         R RRRRRRRRV P                   /p\        V 4      '       g#   \        V P                  P                  4      VR&   V# )	 CLAUDE_CODE_ALWAYS_ENABLE_EFFORTr|  $CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY3ENABLE_TOOL_SEARCHfalse)CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACKSYSTRAY_CODEX_ACCOUNT_SLUGSYSTRAY_CODEX_ACCOUNT_HOME)re   r   rC   rf   r   )r   r  s   & r,   r  r    sU    *C.g3S$hmmK x((478Q8Q8X8X4Y01r7   c               (    V ^8  d   QhRRRRRRRR/# rv  r'   )rF   s   "r,   rG   rG     s)     ! !S !	 !5E !# !r7   c           
        \        V4      p\        V4      p\        V4       \        R 4      pVP                  R,          p\        VR\        \        4      /4       \        W64      p\        V4      ;_uu_ 4       p\        V4       \        P                  ! V.VO\        W@V4      RR7      pVP                  uuRRR4       #   + '       g   i     R# ; i)r+  zclaude-settings.jsonr~  Fr  N)rr  r[  rc  r  rg   r  rH  r]  ry  r  r  rn  r  ro  )	r`  r0  r   claude_argvr   claude_binaryrt  r  r  s	   &&&      r,   	run_proxyr    s    %d+K.x8H *#H-M--0FFM}'8$?O:P&QR%kAK	X		$$X.)[) $7

    
			s   9=CC	c               $    V ^8  d   QhRRRRRR/# ri  r'   )rF   s   "r,   rG   rG     s"      Y *: s r7   c                   ^ RI Hp \        V 4      p\        V4      p\	        R4      p\        V4      p\        V4       \        V4       VP                  R,          p\        VR\        \        4      /4       \        W74      p\        V4      ;_uu_ 4       pVP                  eE   VP                  P                  \         P"                  8X  d   VP$                  P'                  R4      MRp	V! WR7      p
V
P)                  4         \+        VP,                  ;'       g    VP.                  V
P0                  4       \3        WFV
P0                  4      p\        V4       \        V4       \4        P6                  ! V.VOVRR	7      pVP8                  V
P;                  4        uuRRR4       #   T
P;                  4        i ; i  + '       g   i     R# ; i)
r   )HybridRouterr+  zclaudex-hybrid-settings.jsonr~  Nr  )anthropic_base_urlFr  )claudex_routerr  rr  r[  r  r^  rc  rg  rg   r  rH  HYBRID_PICKER_MODELSry  r  rm   r   r   r   r  r   startr  r  rq   r  r  r  rn  ro  stop)r0  r   r  r  r   r  r  rt  r  anthropic_upstreamr  r  r  s   &&           r,   
run_hybridr    sl   +%d+K.x8H#H-M+H5G *w'--0NNM}'8$?S:T&UV%kAK	X		$ ((4))..-2I2II KKOO01 	 	 dJ
	 !6!6!F!F',,X*8fooNJ(2&w/^^--:UF $$KKM' 
	& KKM' 
		s,   A.F;F&A/F&F;&F88F;;G	c                    V ^8  d   QhRRRR/# )r?   r0  r1  rD   rA   r'   )rF   s   "r,   rG   rG     s      Y : r7   c                
   \        V 4       Fs  w  rVP                  R 4      w  r4pVR9  d   K"  T;'       g)    V^,           \        V 4      8  d   W^,           ,          MRp\        P	                  V4      '       g   Kq  Vu # 	  R# )r   r!   N>   -rrO  )r   r5  r   SESSION_ID_PATTERNr7  )r0  r   r:  r;  r*   r<  r   s   &      r,   resumed_session_idr    sr    $T?",,S1))PP%!)c$i2GtAIR	''	22 + r7   c                   V ^8  d   QhRR/# )r?   rD   z
list[Path]r'   )rF   s   "r,   rG   rG     s      z r7   c                    \         P                  ! 4       R ,          R,          .p \        4       R,          pVP                  4       '       d'   V P	                  R VP                  4        4       4       / pV  F;  pVP                  4       '       g   K  VP                  VP                  4       R4       K=  	  \        V4      # )r  projectszclaude-accountsc              3  @   "   T F  qR ,          R,          x  K  	  R# 5i)CLAUDE_HOMEr  Nr'   )r(   r   s   & r,   r-   (session_projects_dirs.<locals>.<genexpr>
  s      
H^-'*44H^s   N)	r   rq   r   is_dirr_  iterdir
setdefaultr  rH  )rootsaccounts_dirseenr  s       r,   session_projects_dirsr    s    YY[9$z12E=#44L 
HTH\H\H^
 	
  D;;==OODLLND1  :r7   c                    V ^8  d   QhRRRR/# )r?   
session_idrC   rD   rh   r'   )rF   s   "r,   rG   rG     s      # + r7   c                    \        4        FL  pVP                  R V  R24       F0  p\        V4      pVf   K  VP                  4       '       g   K,  Vu u # 	  KN  	  R# )z*/z.jsonlN)r  glob_first_recorded_cwdr  )r  projects_dir
transcriptrecordeds   &   r,   session_working_directoryr    sT    -/&++bF,CDJ*:6H#(9(9 E 0
 r7   c                    V ^8  d   QhRRRR/# )r?   r  r   rD   rh   r'   )rF   s   "r,   rG   rG     s      D [ r7   c                    V P                  R R7      ;_uu_ 4       pV Fu  p \        P                  ! V4      p\	        T\
        4      '       g   K2  \	        TP                  R4      \        4      '       g   KY  \        TR,          4      u uuRRR4       # 	  RRR4       R#   \        P                   d     K  i ; i  + '       g   i     R# ; i  \         d     R# i ; i)r   r   rm  N)
r  rZ   r   r   r   r   r   rC   r   rx   )r  r  lineentrys   &   r,   r  r    s    
__g_..& JJt,E eT**z%))E:JC/P/Pe-- /. /  ++ 	 /.   sh   C B>B"B>"B>8B>
C B>C "B;	7B>:B;	;B>>C		C C C! C!c                    V ^8  d   QhRRRR/# r:  r'   )rF   s   "r,   rG   rG   ,  s     ? ?i ?D ?r7   c                    \        V 4      pVf   R # \        V4      pVe   V\        P                  ! 4       8X  d   R # \        P
                  ! V4       \        RV 2\        P                  R7       R # )Nzclaudex: resuming in r  )	r  r  r   rm  r   chdirr  r  r  )r0  r  r  s   &  r,   relocate_to_resumed_sessionr  ,  sW    #D)J(4H8txxz1HHX	!(
,3::>r7   c                    V ^8  d   QhRRRR/# r?   r0  r1  rD   r   r'   )rF   s   "r,   rG   rG   7  s     3 3i 3C 3r7   c                P   \        V 4      w  rV'       dD   \        V 4      w  r VP                  '       d   VP                  f   \	        R4      h\        W4      # \        V 4      w  r VP                  '       d(   VP                  f   VP                  f   \	        R4      h\        \        VP                  4      4       \        V 4       \        V 4      w  r4Vf-   \        V4      '       d   \        \        WB4      # \        WB4      # V\         9   d   \#        W4V4      # \        W4V4      # )Nr   )r,  rE  r   r+  r   rt  r?  r   r)  r  r  rc  r  r  PROXY_MODELr  r^  r  )r0  	seat_moder   r`  r  s   &    r,   rn  rn  7  s    %d+OI5d;'''HOO,C$F  '',T2NH###(>8??CZ B
 	
 $$@$QR%$T*E}3H==[+@@+00$$%h77U22r7   c                    V ^8  d   QhRRRR/# r  r'   )rF   s   "r,   rG   rG   Q  s      y S r7   c                    \        V R ,          4      #   \         d     ^# \         dK   p\        T\        P
                  R7       \        TP                  4       4       TP                  u Rp?# Rp?i\         dd   p\        RT 2\        P
                  R7       \        \        P                  ! TP                  4       RR7      4       TP                  u Rp?# Rp?i\         d2   p\        T\        P
                  R7       TP                  u Rp?# Rp?i\         d*   p\        RT 2\        P
                  R7        Rp?^# Rp?ii ; i)rw  r  Nr3  rU   rW   )rn  KeyboardInterruptr=   r  r  r  r]   r5   r
   rZ   r[   refusal_payloadr/   rx   )r0  r   s   & r,   mainr  Q  s    48}  c

#c !}} 	#cjj1djj,,.:FG}} c

#}} 	#cjj1sg    EEE?A1+E1E>E?ACEE*E+&DEE$E%E		E__main__STALL_GUARD_NOTIFYr|  )r  seatIdhostr`  credentialFingerprint>   AgentWorkflowrX  --agentrY  --tools--agents--plugin	--plugins	--sandboxrv  
--workflow--mcp-config--no-sandbox--plugin-dir--plugin-url--marketplace--allowedTools--allowed-toolsrF  --disallowedTools--enable-workflow--setting-sources--disallowed-tools--enable-workflows--strict-mcp-config)rZ  r[  rG  z--settings=z--setting-sources=z--disallowedTools=z--allowedTools=z--disallowed-tools=z--allowed-tools=z--tools=z	--agents=z--strict-mcp-config=z--mcp-config=z	--plugin=z
--plugins=z--plugin-dir=z--plugin-url=z--marketplace=z--enable-workflows=z--enable-workflow=z--agent=z--workflow=z
--sandbox=z--no-sandbox=))OPUSsolzGPT-5.6 Sol)SONNETterrazGPT-5.6 Terra)HAIKUlunazGPT-5.6 Lunarv   r  )
__future__r   r   r  r  rZ   r   rer  r  r   r"  r  r  r   r  urllib.errorr  urllib.requestcollections.abcr   
contextlibr   dataclassesr   pathlibr   typingr   r	   account_lockr
   r   r   r   r   account_registryr   r   r   authority_clientr   r   r   command_routerr   r   r   r   model_catalogr   routing_resolverr   runtime_pathsr   r  r  r~  r  rp  rQ  r   r5  r4  compiler6  r2  r  r  r!  r?  	frozensetrA  rB  r   valuesr]  r^  HYBRID_CODEX_MODELSr  r  r  ri  r  r  r  r/   r9   r;   r=   rd   rr   r|   r   r   r   r   r   r   r   r   r   r   r  r  r  r(  r*  r  r6  r?  rE  rU  rc  rm  rr  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r&  r)  r,  r8  rC  rK  rQ  rU  r[  r^  rc  rg  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rn  r  r1   r}  r  
SystemExitr0  )r*   rk  rl  s   000r,   <module>rE     sn   "     	 	      
     $ % !    N M 
  ( 3 % * #= 
O 
 -(    JJBC zz+. =>     **@A% '  8 4 --/0 188:; & D-D0CD     8J7IOAeM%%7I  u (uu (  <  	l 	: :$ $d#6 6 $66(K	O4	
>B

 ,5<, $d#& & $& ZZ 34  ww! H>
4	/B#,;  $d#& & $& $d#  $
+!FR7&<
	5p"A	V'1T(P43H
H
 4B UN UNp,0G
!$D?34* zJJ.4
T#((^
$$ q&s   P