+
    jHàj3–  ã                  óš  € 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	H
t
 ^ RIHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ]P0                  ! R
4      t^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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+4      t,R# )-z¤Read-only gateway introspection commands: /status, /context, /usage, /agents, /insights, /topup.
Bound onto ``GatewayRunner`` through ``GatewaySlashCommandsMixin``.)ÚannotationsN)ÚAny)Úfetch_account_usageÚrender_account_usage_lines©Út)ÚPlatform)ÚMessageEvent)ÚTranscriptReadError)Úbuild_status_fieldszgateway.runc               ó    € V ^8„  d   QhRRRR/# )é   Úvaluer   ÚreturnÚstr© )Úformats   "ÚB/home/ubuntu/.hermes/hermes-agent/gateway/slash_commands_status.pyÚ__annotate__r      s   € ÷ Mñ M�cð M˜cñ Mó    c                ó~   € \        V \        4      '       d'   V P                  4       '       d   V P                  4       # R# )z;Strip and return a non-empty string value, or empty string.Ú )Ú
isinstancer   Ústrip©r   s   &r   Ú
_clean_strr      s)   € ä& u¬c×2Ò2°u·{±{·}²}ˆ5�;‰;‹=ÐLÈ"ÐLr   c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   Úintr   )r   s   "r   r   r       s   € ÷ ñ �cð ˜cñ r   c                óJ   €  \        V 4      #   \        \        3 d     ^ # i ; i)zSafely coerce to int.)r   Ú	TypeErrorÚ
ValueErrorr   s   &r   Ú
_int_valuer!       s(   € ðÜ�5‹zÐøÜ”zÐ"ô Úðús   ‚
 �"¡"c               ó   € V ^8„  d   QhRR/# )r   Úattrr   r   )r   s   "r   r   r   (   s   € ÷ &ñ &�#ñ &r   c                ó.   € \        W^ 4      ;'       g    ^ # )é    ©Úgetattr)Úobjr#   s   &&r   Ú_nr)   (   s   € Ü�3˜aÓ ×%Ð% AÐ%r   c               ó   € V ^8„  d   QhRR/# ©r   r   r   r   )r   s   "r   r   r   ,   s   € ÷ ñ ˆsñ r   c                ó
   € V R  # )Ú,r   )Úns   &r   Ú_fmtr/   ,   s   € Ø�ˆU€Or   c               ó   € V ^8„  d   QhRR/# )r   r   Úfloatr   )r   s   "r   r   r   0   s   € ÷ 8ñ 8˜ñ 8r   c                óH   € V'       d   \        ^dW,          ^d,          4      # ^ # )éd   )Úmin)ÚusedÚtotals   &&r   Ú_pctr7   0   s   € ß+0Œ3ˆs�D•L 3Õ&Ó'Ð7°aÐ7r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Útextr   Úlimitr   r   r   )r   s   "r   r   r   4   s&   € ÷ Dñ D�ð D˜Cð D Cñ Dr   c                óL   € \        V 4      V8”  d   V R V^,
           R,           # T # )Nz...)Úlen)r9   r:   s   &&r   Ú_clipr=   4   s(   € Ü(+¨D«	°EÔ(9ˆ4��%˜!•)Ð˜uÕ$ÐC¸tÐCr   c               ó   € V ^8„  d   QhRR/# )r   r   ztuple[int, int]r   )r   s   "r   r   r   8   s   € ÷ ;ñ ; _ñ ;r   c                óÀ   € ^ RI Hp V  Uu. uF5  q"P                  R4      R9   g   K  VP                  R4      '       g   K3  VNK7  	  ppV! V4      \        V4      3# u upi )zT``(approx_tokens, message_count)`` over the user/assistant messages of a transcript.)Úestimate_messages_tokens_roughÚroleÚcontent>   ÚuserÚ	assistant)Úagent.model_metadatar@   Úgetr<   )Úhistoryr@   ÚmÚmsgss   &   r   Ú_transcript_estimaterJ   8   sQ   € åCÙÓ^‘w�!§%¡%¨£-Ð3HÑ"HŒAÈQÏUÉUÐS\×M]�AˆA‘w€DÐ^Ù)¨$Ó/´°T³Ð:Ð:ùò _s   ‹A§AÁ Ac              ƒ  óT   "  €  V ! 4       G Rj  x€L
 #  L  \          d    Tu # i ; i5i)zVAwait ``call()`` fail-open: any exception (sync or in the awaitable) yields *default*.N©Ú	Exception©ÚcallÚdefaults   &&r   Ú_quietrQ   ?   s)   é € ðÙ“V�|Ð‰|øÜô ØŠðüs(   ‚(„
 Ž� ’(“ •%¢(¤%¥(u°   âš ï¸� I can't read this conversation's history right now (your earlier messages exist but cannot be loaded). Run `hermes doctor --fix` on the host, or use /new to start fresh.c               ó   € V ^8„  d   QhRR/# r+   r   )r   s   "r   r   r   N   s   € ÷ 2ñ 2˜Cñ 2r   c                 ó   € \        R 4      # )z!gateway.shared.history_unreadabler   r   r   r   Úhistory_unreadablerT   N   s   € ÜÐ0Ó1Ð1r   c               ó   € V ^8„  d   QhRR/# r+   r   )r   s   "r   r   r   R   s   € ÷ Xñ X˜cñ Xr   c                 óÔ   € ^ RI Hp  V ! 4       p\        V\        4      '       d   VP	                  R/ 4      M/ p\        V\        4      '       d   \        VP	                  R4      4      # R# )z;``model.provider`` from the gateway config ("" when unset).)Ú_load_gateway_configÚmodelÚproviderr   )Úgateway.runrW   r   ÚdictrF   r   )rW   Úuser_configÚ	model_cfgs      r   Ú_configured_providerr^   R   sR   € å0Ù&Ó(€KÜ0:¸;Ì×0MÒ0M�—‘ ¨Ô,ÐSU€IÜ4>¸yÌ$×4OÒ4OŒ:�i—m‘m JÓ/Ó0ÐWÐUWÐWr   c                ó8   €  V ! 4       #   \          d    Tu # i ; i)zSync twin of ``_quiet``.rL   rN   s   &&r   Ú_quiet_syncr`   Z   s"   € ðÙ‹vˆøÜô ØŠðús   ‚	 ‰˜c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úactive_overrider[   Úpersisted_routeÚsession_rowr   )r   s   "r   r   r   b   s)   € ÷ *hñ *hØ#'ð*hØ:>ð*hØMQñ*hr   c                ó   € ^ RI HpHpHp ^ ;r‰. p
V eµ   WJd°   V
P	                  \        \        V RR4      4      \        \        V RR4      4      R\        \        V RR4      4      R\        \        V RR4      4      /34       \        V RR4      pVe7   \        ^ \        \        VR	^ 4      4      4      p\        \        VR
^ 4      4      p	V
P	                  \        VP                  R4      4      \        VP                  R4      4      R\        VP                  R4      4      R\        VP                  R4      4      /34       V
P	                  \        VP                  R4      4      \        VP                  R4      4      / 34       \        VP                  R4      4      \        VP                  R4      4      / 3p\        R V
 4       V4      w  rÞpT;'       g    \        \        VR	^ 4      4      p/ pV'       d	   V'       g   \        V/ 4      p\        V\        4      '       d   VP                  R/ 4      M/ p\        V\        4      '       d   TM/ pT;'       g	    V! V4      pT;'       g    \        VP                  R4      4      pWÞW‰RV/VC3# )a  ``(model, provider, context_used, context_total, route)`` for /status.

Order: live/cached agent route -> active session override -> persisted recent route ->
SessionDB row -> gateway config (only loaded when something is still missing). ``route`` carries
the ``provider`` / ``base_url`` / ``api_key`` of the winning source only, so a later context-window
lookup queries the endpoint that serves the displayed model (never a losing route's endpoint);
a winner without a ``base_url`` leaves the lookup on the default runtime route.
)Ú_AGENT_PENDING_SENTINELrW   Ú_resolve_gateway_modelNrX   r   rY   Úbase_urlÚapi_keyÚcontext_compressorÚlast_prompt_tokensÚcontext_lengthÚbilling_providerc              3  óh   "  € T F(  q^ ,          '       g   K  V^,          '       g   K$  Vx € K*  	  R# 5i)r%   Nr   )Ú.0Úrs   & r   Ú	<genexpr>Ú&_status_model_route.<locals>.<genexpr>�   s"   é € Ð,P¹°1ÀAÇ$Á$¬QÈ1ÈQÏ4É4¯QªQ»ùs   ‚2—2¨
2)rZ   rf   rW   rg   Úappendr   r'   Úmaxr!   rF   Únextr`   r   r[   )Ústatus_agentrb   rc   rd   Úsession_entryrf   rW   rg   Úcontext_usedÚcontext_totalÚroutesÚctxÚ	row_routeÚ
model_nameÚprovider_nameÚrouter\   r]   s   &&&&&             r   Ú_status_model_router€   b   s`  € ÷ bÑaØ#$Ð$€LØ*,€FØÒ LÓ$OØ�‰”z¤'¨,¸ÀÓ"DÓEÜ!¤'¨,¸
ÀBÓ"GÓHØ"¤J¬w°|ÀZÐQSÓ/TÓ$UØ!¤:¬g°lÀIÈrÓ.RÓ#SðUðVô 	Wô �lÐ$8¸$Ó?ˆØŠ?Ü˜q¤*¬W°SÐ:NÐPQÓ-RÓ"SÓTˆLÜ&¤w¨sÐ4DÀaÓ'HÓIˆMØ
‡M�M”:˜o×1Ñ1°'Ó:Ó;Ü˜o×1Ñ1°*Ó=Ó>Ø¤
¨?×+>Ñ+>¸zÓ+JÓ KØœz¨/×*=Ñ*=¸iÓ*HÓIðKðLô Mð ‡M�M”:˜o×1Ñ1°'Ó:Ó;Ü˜o×1Ñ1Ð2DÓEÓFÈðLô Mä˜KŸO™O¨GÓ4Ó5´zÀ+Ç/Á/ÐRdÓBeÓ7fÐhjÐk€Iä'+Ñ,P¹Ó,PÐR[Ó'\Ñ$€J˜uØ×^Ð^¤:¬g°mÐEYÐ[\Ó.]Ó#^€LØ"$€KßŸ]Ü!Ð"6¸Ó;ˆÜ0:¸;Ì×0MÒ0M�—‘ ¨Ô,ÐSU€IÜ'¨	´4×8Ò8‘	¸b€IØ×BÐBÑ5°kÓB€JØ!×JÐJ¤Z°	·±¸jÓ0IÓ%J€Mð  lÀJÐP]ÐCgÐafÐCgÐgÐgr   c               ó    € V ^8„  d   QhRRRR/# )r   r5   r   r   ú	list[str]r   )r   s   "r   r   r   �   s   € ÷ ñ °ð ¸	ñ r   c                ó<  € . p^ RI Hp V! V4      R8w  d   RMRp\        VR4      p\        VR4      ^d,          R pV^ 8”  dj   W&8¼  d(   VP                  \	        R\        V4      VR	7      4       M<VP                  \	        R
\        V4      Wu\        Wb,
          4      ,           R7      4       \        VR4      pVP                  \	        RVR7      4       V'       d   \        VRR4      MRp	V	e   VP                  \	        RV	R R7      4       VR\	        R\        V R4      R7      \	        R\        \        V R4      4      \        \        V R4      4      \        \        V R4      4      R7      \	        R\        \        V R4      4      R7      \	        R4      .,          pV# )z /context full view: auto-compression threshold/headroom, compression count + last savings,
and cumulative throughput (labelled as throughput, NOT context size).©Úcontext_display_sourceÚprovider_usageÚ~r   Úthreshold_tokensÚthreshold_percentú.0fzgateway.context.over_threshold)Ú	thresholdÚthreshold_pctzgateway.context.threshold)r‹   rŒ   Úto_goÚcompression_countzgateway.context.compressions©ÚcountÚ_last_compression_savings_pctNzgateway.context.last_savings)Úsavingszgateway.context.totals_headerÚsession_api_calls)Úcallszgateway.context.totals_lineÚsession_input_tokensÚsession_output_tokensÚsession_reasoning_tokens)ÚinputÚoutputÚ	reasoningzgateway.context.total_billedÚsession_total_tokens©r6   zgateway.context.throughput_note)Úagent.context_breakdownr…   r)   rs   r   r/   r'   )
Úagentr{   r5   Úlinesr…   Úmarkr‹   rŒ   Úcompressionsr’   s
   &&&       r   Ú_context_compressor_linesr¢   �   s~  € ð €EÝ>Ù(¨Ó-Ð1AÔA‰3Àr€DÜ�3Ð*Ó+€IÜ˜#Ð2Ó3°cÕ9¸#Ð>€MØ�1„}ØÔØ�L‰LœÐ;ÄtÈIÃØ)6ô8õ 9ð �L‰LœÐ6Ä$ÀyÃ/Ø)6ÄTÈ)ÕJZÓE[Õ>[ô]ô ^ä�cÐ.Ó/€LØ	‡L�L”Ð1¸ÔFÔGßEQŒg�cÐ:¸DÔAÐW[€GØÒØ�‰”QÐ5À'È#ÀÔPÔQØ	Ø
Ü	Ð
)´°EÐ;NÓ1OÔPÜ	Ð
'Ü”R˜Ð5Ó6Ó7Ü”b˜Ð 7Ó8Ó9Üœ˜EÐ#=Ó>Ó?ô	Aô 	
Ð
(´´R¸Ð?UÓ5VÓ0WÔXÜ	Ð
+Ó,ð	õ 	€Eð €Lr   c               ó    € V ^8„  d   QhRRRR/# )r   Údr[   r   r‚   r   )r   s   "r   r   r   °   s   € ÷ ñ  ð ¨ñ r   c           	     óš  € \        RP                  \        V P                  R4      ;'       g    R4      P	                  4       4      ^F4      pV P                  RR4      pRV P                  RR4       RV 2pV P                  R	4      pVR
8X  d   Ve   V\        RVR R7      ,          pM;VR
8w  d5   V P                  R^ 4      ^<8¼  d   V\        RV R,          R R7      ,          pV'       d   VRV 2,          pV.p\        V P                  R4      ;'       g    . 4       F¨  w  rg\        V\        4      '       g   K  VP                  R4      pV'       d   RV R2M
\        R4      p	\        RV^,           VP                  RR4      V	R7      p
VP                  R4      pTP                  Y«e   \        RVR R7      MR,           4       Kª  	  V# )z¥/agents rows for one background delegation. Live per-child activity comes from the
registry's progress sampler: api calls, current tool, seconds since last activity.Ú Úgoalr   ÚstatusÚ?ú- `Údelegation_idõ   ` Â· Ústalled_after_quiet_secondsÚstallingzgateway.agents.no_progressrŠ   )ÚsecondsÚseconds_since_progresszgateway.agents.quiet_forõ    Â· Úchildren_activityÚcurrent_toolÚ`zgateway.agents.between_turnszgateway.agents.child_rowÚ	api_calls)Úindexr”   ÚdoingÚseconds_since_activityzgateway.agents.active_ago)
r=   Újoinr   rF   Úsplitr   Ú	enumerater   r[   rs   )r¤   r§   r¨   ÚrowÚquietrŸ   ÚiÚchildÚtoolr·   ÚpartÚidles   &           r   Ú_agents_delegation_linesrÃ   °   sž  € ô �—‘œ#˜aŸe™e F›m×1Ð1¨rÓ2×8Ñ8Ó:Ó;¸RÓ@€DØ�U‰U�8˜SÓ!€FØ�—‘�o sÓ+Ð,¨E°&°Ð
:€CØ�E‰EÐ/Ó0€EØ�Ô Ò 1ØŒqÐ-¸%À¸ÔFÕF‰Ø	�:Ô	 !§%¡%Ð(@À!Ó"DÈÔ"JØŒqÐ+¸Ð:RÕ8SÐTWÐ7XÔZÕZˆßØ��d�Vˆ}ÕˆØˆE€EÜ˜aŸe™eÐ$7Ó8×>Ð>¸BÖ?‰ˆÜ˜%¤×&Ò&ÙØ�y‰y˜Ó(ˆß#�!�D�6˜‘¬Ð+IÓ)JˆÜÐ+°1°qµ5ÀÇ	Á	È+ÐWZÓ@[ÐchÔiˆØ�y‰yÐ1Ó2ˆØ�‰�TÒVfœQÐ:ÀtÈCÀjÕRÐlnÕoÖpñ @ð €Lr   c               ó   € V ^8„  d   QhRR/# ©r   r   r‚   r   )r   s   "r   r   r   É   s   € ÷ ñ  yñ r   c                ó’  € . pV P                  4       pV'       d5   VP                  '       d#   ^ RIHp V\	        RV! V4      R7      R.,          pV\	        R4      \	        RV P
                  R7      \	        R\        \        V R	4      4      R
7      \	        R\        \        V R4      4      R
7      \	        R\        V P                  4      R
7      \	        RV P                  R
7      .,          pV P                  pVP                  ^ 8”  dˆ   \        VP                  VP                  4      p^ RIHp V! V4      R8w  d   RMRpVP!                  \	        RV\        VP                  4      ,           \        VP                  4      V VR 2R7      4       VP"                  '       d'   VP!                  \	        RVP"                  R
7      4       V# )z|/usage session block for a live agent: rate limits, token breakdown (matches the CLI),
context window and compression count.)Úformat_rate_limit_compactzgateway.usage.rate_limits©Ústater   zgateway.usage.header_sessionzgateway.usage.label_model©rX   z gateway.usage.label_input_tokensr•   r�   z!gateway.usage.label_output_tokensr–   zgateway.usage.label_totalzgateway.usage.label_api_callsr„   r†   r‡   zgateway.usage.label_contextrŠ   ©r5   r6   Úpctz gateway.usage.label_compressions)Úget_rate_limit_stateÚhas_dataÚagent.rate_limit_trackerrÇ   r   rX   r/   r)   r›   r“   rj   rk   r7   rl   r�   r…   rs   rŽ   )rž   rŸ   Úrl_staterÇ   r{   rÌ   r…   r    s   &       r   Ú_usage_agent_stats_linesrÑ   É   s  € ð €EØ×)Ñ)Ó+€Hß�H×%×%Ð%ÝFØ”!Ð/Ñ7PÐQYÓ7ZÔ[Ð]_Ð`Õ`ˆØ	Ü	Ð
(Ó)Ü	Ð
%¨U¯[©[Ô9Ü	Ð
,´D¼¸EÐCYÓ9ZÓ4[Ô\Ü	Ð
-´T¼"¸UÐD[Ó:\Ó5]Ô^Ü	Ð
%¬T°%×2LÑ2LÓ-MÔNÜ	Ð
)°×1HÑ1HÔIðõ €Eð ×
"Ñ
"€CØ
×Ñ Ô!Ü�3×)Ñ)¨3×+=Ñ+=Ó>ˆÝBÙ,¨SÓ1Ð5EÔE‰sÈ2ˆØ�‰”QÐ4¸4Ä$Às×G]ÑG]ÓB^Õ;^Ü! #×"4Ñ"4Ó5¸d¸VÀCÈÀ9Ð;MôOô 	Pà
××ÐØ�‰”QÐ9À×AVÑAVÔWÔXØ€Lr   c               ó    € V ^8„  d   QhRRRR/# )r   ÚitemsÚlistr   r‚   r   )r   s   "r   r   r   å   s   € ÷ ñ ˜ð ¨ñ r   c                óà   € . pV R\           F  pVP                  V! V4      4       K  	  \        V 4      \         8”  d1   VP                  \	        R\        V 4      \         ,
          R7      4       V# )zYRender up to ``_LIST_CAP`` items via *render* (list of lines each) plus an overflow line.Nzgateway.agents.morer�   )Ú	_LIST_CAPÚextendr<   rs   r   )rÓ   ÚrenderrŸ   Úitems   &&  r   Ú_capped_rowsrÚ   å   sV   € à€EØ�j”yÓ!ˆØ�‰‘V˜D“\Ö"ñ "ä
ˆ5ƒz”IÔØ�‰”QÐ,´C¸³JÄÕ4JÔKÔLØ€Lr   c                  óÄ   € ] tR t^ïtRtR R ltR R lt]R R l4       tR R	 lt	R
 t
RR R l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 tR R ltRtR# )ÚGatewayStatusCommandsMixinz`Read-only gateway introspection commands: /status, /context, /usage, /agents, /insights, /topup.c               ó    € V ^8„  d   QhRRRR/# ©r   Úeventr	   r   r   r   )r   s   "r   r   Ú'GatewayStatusCommandsMixin.__annotate__ò   s   € ÷ K ñ K °,ð K À3ñ K r   c              ƒ  ó|
  "  € ^ RI Hp VP                  pV P                  P	                  V4      G Rj  x€L
 pVP
                  pV P                  P                  V4      pVRJ;'       d    WbJpV'       d&   V P                  P                  VP                  4      MRpV P                  WXR7      p	V P                  VP                  4      G Rj  x€L
 w  r«rÍV'       d   TMV P                  V4      pV P                  V4       V P                  V4      ;'       g    / p\!        WïWÛV4      w  pppppV'       gN   V'       dF   V P#                  VVV4      G Rj  x€L
 pVe'   VP$                  R8w  d   \'        VP(                  4      p\+        VP                  RWºVVVP,                  VP.                  WÇR7
      p\1        R4      R\1        RVR	,          R
7      .pVR,          '       d$   VP3                  \1        RVR,          R7      4       V\1        RVR,          R7      \1        RVR,          R7      .,          pVR,          '       d<   VR,          '       d-   VP3                  \1        RVR,          VR,          R7      4       M2VR,          '       d$   VP3                  \1        RVR,          R7      4       ^ RIHp V! \9        VRR4      4      R8w  d   RMRpV'       d`   \;        ^d\=        VV,          ^d,          4      4      pVP3                  \1        RV\?        V4      ,           \?        V4      V V 2R7      4       M4V'       d-   VP3                  \1        RV\?        V4      ,           R 7      4       VR!,          '       d   \1        R"4      M
\1        R#4      pV\1        R$VR%,          R&7      \1        R'VR(7      .,          pV	'       d   VP3                  \1        R)V	R*7      4       VP                  \@        PB                  8X  dî   \9        V P                  P                  \@        PB                  4      R+\D        PF                  ! R,R-4      4      pTR\1        R.4      \1        R/VPH                  ;'       g    VPJ                  R07      \1        R1VPJ                  R27      \1        R3VPL                  ;'       g    \1        R44      R57      \1        R6VR77      \1        R8V PO                  V4      R97      .,          pVR\1        R:R;PQ                  R< V P                   4       4      R=7      .,          pR>PQ                  V4      #  EL  ELi ELä5i)?zHandle /status command.©rf   N)ÚadapterrP   )ÚtitlerX   rY   ÚcreatedÚlast_activityÚtokensÚagent_runningzgateway.status.headerr   zgateway.status.session_idÚ
session_id)ré   rä   zgateway.status.title)rä   zgateway.status.createdrå   )Ú	timestampzgateway.status.last_activityræ   rX   rY   zgateway.status.model_provider)rX   rY   zgateway.status.modelrÊ   r„   rj   r†   r‡   zgateway.status.contextrË   zgateway.status.context_used)r5   rè   zgateway.status.state_yeszgateway.status.state_nozgateway.status.tokensrç   )rç   zgateway.status.agent_runningrÈ   zgateway.status.queuedr�   Ú_matrix_session_scopeÚMATRIX_SESSION_SCOPEÚautoz"gateway.status.matrix_scope_headerz gateway.status.matrix_scope_room)Úroomz#gateway.status.matrix_scope_room_id)Úroom_idz"gateway.status.matrix_scope_threadzgateway.shared.none_value)Ú	thread_idz gateway.status.matrix_scope_mode)Úscopezgateway.status.matrix_scope_key)Úsession_keyzgateway.status.platformsz, c              3  ó8   "  € T F  qP                   x € K  	  R # 5i©Nr   )ro   Úps   & r   rq   ÚDGatewayStatusCommandsMixin._handle_status_command.<locals>.<genexpr><  s   é € ÐGgÑYfÐTUÏÎÓYfùs   ‚)Ú	platformsÚ
))rZ   rf   ÚsourceÚasync_session_storeÚget_or_create_sessionrò   Ú_running_agentsrF   ÚadaptersÚplatformÚ_queue_depthÚ_status_session_db_factsré   Ú_cached_agent_forÚ!_rehydrate_session_model_overrideÚ_session_model_overrider€   Ú_resolve_route_contextÚcontext_sourcer!   rl   r   Ú
created_atÚ
updated_atr   rs   r�   r…   r'   r4   Úroundr/   r   ÚMATRIXÚosÚgetenvÚ	chat_nameÚchat_idrð   Ú_redact_matrix_session_keyr¹   )Úselfrß   rf   rù   rw   rò   rž   Ú
is_runningrã   Úqueue_depthrä   rd   Údb_total_tokensrc   rv   rb   r}   r~   rx   ry   r   ÚresolvedÚfieldsrŸ   r…   r    rÌ   rÉ   rñ   s   &&                           r   Ú_handle_status_commandÚ1GatewayStatusCommandsMixin._handle_status_commandò   sc  é € å7Ø—‘ˆØ"×6Ñ6×LÑLÈVÓT×TˆØ#×/Ñ/ˆð ×$Ñ$×(Ñ(¨Ó5ˆØ $Ð&×OÐO¨5Ð+Oˆ
ç8>�$—-‘-×#Ñ# F§O¡OÔ4ÀDˆØ×'Ñ'¨Ð'ÓEˆØEI×EbÑEbØ×$Ñ$óF
÷ @
Ñ<ˆ˜O÷ !+‘u°×0FÑ0FÀ{Ó0SˆØ×.Ñ.¨{Ô;Ø×6Ñ6°{ÓC×IÐIÀrˆÜH[Ø¨?ÈóI
ÑEˆ
�M <°À÷ §ð "×8Ñ8¸ÀÈUÓS×SˆHØÒ#¨×(?Ñ(?À9Ô(LÜ *¨8×+BÑ+BÓ C�ä$Ø×$Ñ$ d¨KÈJÐanØ!×,Ñ,¸M×<TÑ<TØ"ô
ˆô
 Ð*Ó+¨RÜÐ.¸6À,Õ;OÔPðRˆà�'�?Œ?Ø�L‰LœÐ1¸À½ÔIÔJØ”!Ð,¸¸yÕ8IÔJÜÐ2¸fÀ_Õ>UÔVðXõ 	Xˆà�'�?Œ?˜v j×1Ô1Ø�L‰LœÐ:À&ÈÅ/Ð\bÐcmÕ\nÔoÕpØ�G�_Œ_Ø�L‰LœÐ1¸À½ÔIÔJÝBÙ,¬W°\ÐCWÐY]Ó-^Ó_ÐcsÔs‰sÐy{ˆßÜ�cœ5 ,°Õ">À#Õ!EÓFÓGˆCØ�L‰LœÐ3¸$ÄÀlÓASÕ:SÔ[_Ð`mÓ[nØ"& ¨ u˜~ô/õ 0çØ�L‰LœÐ8¸tÄdÈ<ÓFXÕ?XÔYÔZØ17¸×1HÔ1H”Ð,Ô-ÌaÐPiÓNjˆØ”!Ð+°F¸8Õ4DÔEÜÐ2¸%Ô@ðBõ 	BˆçØ�L‰LœÐ2¸+ÔFÔGØ�?‰?œhŸo™oÔ-Ü˜DŸM™M×-Ñ-¬h¯o©oÓ>Ð@WÜŸIšIÐ&<¸fÓEóGˆEàØÜÐ6Ó7ÜÐ4¸6×;KÑ;K×;]Ð;]ÈvÏ~É~Ô^ÜÐ7ÀÇÁÔPÜÐ6À&×BRÑBR×BtÐBtÔVWÐXsÓVtÔuÜÐ4¸EÔBÜÐ3Ø"×=Ñ=¸kÓJôLð	õ 	ˆEð 	�"”aÐ2¸d¿i¹iÑGgÐY]×YfÒYfÓGgÓ>gÔhÐiÕiˆØ�y‰y˜ÓÐòO Uò@
ò  Tùsv   ‚1T<³T3´5T<Á*T<Á6AT<ÃT6ÃA
T<Ä%T<Ä?T<ÅT9ÅC=T<É:T<ÊAT<ËA&T<Í:T<Í>D.T<Ò-BT<Ô6T<Ô9T<c               ó   € V ^8„  d   QhRR/# )r   ré   r   r   )r   s   "r   r   rà   ?  s   € ÷ ]ñ ]¸ñ ]r   c              ƒ  ó|  aaa"  € V P                   oS'       g   R/ ^ / 3# \        VV3R l4      G Rj  x€L
 p\        VV3R l4      G Rj  x€L
 p\        V\        4      '       d   TM/ o\	        V3R lR 4       4      p\        VV3R l4      G Rj  x€L
 pTST\        V\        4      '       d   V3# / 3#  L‚ Ll L'5i)a  ``(title, session_row, db_total_tokens, persisted_route)`` for /status; each fail-open.

Token totals come from the SQLite session DB, not SessionStore: run_agent.py persists per-turn
token deltas into sessions_db, never into SessionEntry (its total_tokens is always 0).
Nc                 ó&   <€ S P                  S4      # rô   )Úget_session_title©Údbré   s   €€r   Ú<lambda>ÚEGatewayStatusCommandsMixin._status_session_db_facts.<locals>.<lambda>H  s   ø€  R×%9Ñ%9¸*Ô%Er   c                 ó&   <€ S P                  S4      # rô   )Úget_sessionr  s   €€r   r  r  I  s   ø€  2§>¡>°*Ô#=r   c              3  óX   <"  € T F  p\        SP                  V4      4      x € K!  	  R # 5irô   )r!   rF   )ro   Úkrd   s   & €r   rq   ÚFGatewayStatusCommandsMixin._status_session_db_facts.<locals>.<genexpr>K  s)   øé € ð 
áu�ô �{—‘ qÓ)×*Ð*Ûuùs   ƒ'*c                 ó&   <€ S P                  S4      # rô   )Úget_recent_session_model_router  s   €€r   r  r  O  s   ø€  R×%FÑ%FÀzÔ%Rr   )Úinput_tokensÚoutput_tokensÚcache_read_tokensÚcache_write_tokensÚreasoning_tokens)Ú_session_dbrQ   r   r[   Úsum)r  ré   rä   r¼   r  r   r  rd   s   &f    @@r   r   Ú3GatewayStatusCommandsMixin._status_session_db_facts?  s­   úé € ð ×ÑˆßØ˜˜Q �?Ð"ÜÕEÓF×FˆÜÕ=Ó>×>ˆÜ'¨¬T×2Ò2‘c¸ˆÜô 
áuó
ó 
ˆô ÕRÓS×SˆØ�k ?¼ZÈÌt×=TÒ=T°EÐ\Ð\ÐZ\Ð\Ð\ñ GÙ>ñ Tùs4   ….B<³B6´B<ÁB8ÁAB<ÂB:Â$B<Â8B<Â:B<c               ó    € V ^8„  d   QhRRRR/# )r   rò   r   r   r   )r   s   "r   r   rà   S  s   € ÷ "ñ "°ð "¸ñ "r   c                ó¦   € \         P                  ! \        T ;'       g    R4      P                  R4      4      P	                  4       R,          pRV 2# )zFReturn a stable Matrix session-key fingerprint for shared room status.r   zutf-8:Né   Nzsha256:)ÚhashlibÚsha256r   ÚencodeÚ	hexdigest)rò   Údigests   & r   r  Ú5GatewayStatusCommandsMixin._redact_matrix_session_keyR  sF   € ô —’¤ K×$5Ð$5°2Ó 6× =Ñ =¸gÓ FÓG×QÑQÓSÐTWÕXˆØ˜˜Ð!Ð!r   c               ó    € V ^8„  d   QhRRRR/# rÞ   r   )r   s   "r   r   rà   X  s   € ÷ 3ñ 3°<ð 3ÀCñ 3r   c              ƒ  ó$  "  € VP                   pV P                  P                  V4      G Rj  x€L
 pVP                  4       P	                  4       P                  4       R9   pV P                  V P                  V4      4      ;'       g    RpV'       d   \        VRR4      MRpV P                  WVW24      G Rj  x€L
 w  rxp	^ RI
Hp
 V
! V4      R8w  d   RMRpV^ 8”  Edƒ   V^ 8”  Ed{   \        Wx4      p\        V^d,          ^,          4      p\        R4      R\        RT	;'       g    R	R
7      \        R\        V4      R7      \        RV\        V4      ,           \        V4      V VR 2R7      \        RR\!        ^ V4      ,          R\!        ^ ^V,
          4      ,          ,           R7      \        RV\        \!        ^ W‡,
          4      4      ,           R7      R.pYæe   \#        WVV4      M\        R4      .,          pV'       d+   \$        P&                  ! V P(                  WRV4      G Rj  x€L
 M. pRP+                  Yï'       d   R.V,           ,           4      # . ,           4      #  V P                  P-                  VP.                  4      G Rj  x€L
 pT'       g   \        R4      # \5        T4      w  ppRP+                  \        R4      R\        R\        T4      TR7      \        R4      .4      #  EL¾ EL7 LÊ Li  \0         d    \3        4       u # i ; i5i)uf  Handle /context â€” the deep context-window view (/status has the one-line summary).

Gauge, auto-compression threshold/headroom, compression count + last savings, and cumulative
throughput (labelled as throughput, NOT context size). Resolution: running agent -> cached
agent -> SessionStore/SessionDB metadata -> transcript estimate. ``all`` adds listings.
Nrj   r„   r†   r‡   r   zgateway.context.headerzgateway.context.modelr©   rÊ   zgateway.context.windowrœ   zgateway.context.in_userŠ   rË   zgateway.context.baru   â–ˆu   â–‘)Úbarzgateway.context.headroom)Úheadroomz"gateway.context.detail_after_firstrø   zgateway.context.no_datazgateway.context.estimated)r�   Úmessages>   ÚallÚfullÚdetails)rù   rú   rû   Úget_command_argsr   ÚlowerÚ_resident_agent_forÚ_session_key_for_sourcer'   Ú_resolve_context_figuresr�   r…   r7   r  r   r/   rt   r¢   ÚasyncioÚ	to_threadÚ_context_breakdown_blockr¹   Úload_transcriptré   r
   rT   rJ   )r  rß   rù   rw   Úexpandedrž   r{   r5   rl   r}   r…   r    rÌ   ÚfilledrŸ   Ú	breakdownrG   Úapproxr�   s   &&                 r   Ú_handle_context_commandÚ2GatewayStatusCommandsMixin._handle_context_commandX  sÂ  é € ð —‘ˆØ"×6Ñ6×LÑLÈVÓT×TˆØ×)Ñ)Ó+×1Ñ1Ó3×9Ñ9Ó;Ð?YÑYˆà×(Ñ(¨×)EÑ)EÀfÓ)MÓN×VÐVÐRVˆß<AŒg�eÐ1°4Ô8ÀtˆØ15×1NÑ1NØ˜ó2
÷ ,
Ñ(ˆ˜jõ 	CÙ,¨SÓ1Ð5EÔE‰sÈ2ˆà�!�8˜¨Õ*Ü�tÓ,ˆCÜ˜3 �9 r�>Ó*ˆFäÐ*Ó+¨RÜÐ)°×1BÐ1B¸sÔCÜÐ*´$°~Ó2FÔGÜÐ*°¼¸T»
Õ1BÌ$È~ÓJ^ÐgkÐflÐmpÐqtÐluÐdvÔwÜÐ'¨U´S¸¸F³^Õ-CÀeÌcÐRSÐUWÐZ`ÕU`ÓNaÕFaÕ-aÔbÜÐ,°t¼dÄ3ÀqÈ.ÕJ_ÓC`Ó>aÕ7aÔbØðˆEð ÂOÔ.¨u¸4Ô@ÜÐ6Ó7ðZ9õ 9ˆE÷
 lqœg×/Ò/°×0MÑ0MÈuÐ^fÓg×gÐgÐvxˆIØ—9‘9˜U¾) r d¨YÕ&6ÕLÓMÐMÈÕLÓMÐMð	(Ø ×4Ñ4×DÑDÀ]×E]ÑE]Ó^×^ˆG÷ ÜÐ.Ó/Ð/Ü,¨WÓ5‰ˆ�Ø�y‰yÜÐ&Ó'¨ÜÐ)´°f³ÈÔNÜÐ2Ó3ð
ó ð 	òO Uò
,
ñ0 hñ _øÜ"ô 	(Ü%Ó'Ò'ð	(üs~   ‚+L­K+®A$LÂ$LÂ7K.Â8ELÈ%LÈ&K1È'9LÉ!(K5 Ê	K3Ê
K5 ÊLÊALË.LË1LË3K5 Ë5LÌ
LÌLÌLc           
   ƒ  óÌ  a aa	a
"  € \        ^ \        VR4      4      ;'       g!    \        ^ \        \        SR^ 4      4      4      p\        VR4      pVe   \	        \        VRR4      4      MRo
S
'       g^   S P
                  '       dL   \        V V3R l4      G Rj  x€L
 p\        V\        4      '       d   \	        VP                  RR4      4      MRo
V'       gJ   S P                  VS
4      G Rj  x€L
 pVe,   S
;'       g    VP                  o
\        VP                  4      pV'       g0   S
'       d(   ^ RIHo	 \        \        V	V
3R l4      G Rj  x€L
 4      pWVS
3#  LÃ Lp L5i)	zµ``(used, context_length, model_name)`` for /context: used = compressor -> SessionStore;
model = agent -> SessionDB row; window = compressor -> gateway model route -> model metadata.rk   rl   NrX   r   c                 óN   <€ S P                   P                  SP                  4      # rô   )r+  r   ré   )r  rw   s   €€r   r  ÚEGatewayStatusCommandsMixin._resolve_context_figures.<locals>.<lambda>”  s   ø€  t×'7Ñ'7×'CÑ'CÀM×D\ÑD\Ô']r   )Úget_model_context_lengthc                 ó2   <€ \         P                  ! S S4      # rô   ©rD  rE  )rQ  r}   s   €€r   r  rP  ž  s   ø€ ¤W×%6Ò%6Ð7OÐQ[Ô%\r   )rt   r)   r!   r'   r   r+  rQ   r   r[   rF   r  rX   rl   rE   rQ  )r  rž   r{   rw   rù   r5   rl   r¼   r  rQ  r}   s   f&&f&    @@r   rC  Ú3GatewayStatusCommandsMixin._resolve_context_figures�  s   ûé € ô �1”b˜Ð2Ó3Ó4×{Ð{¼¸A¼zÌ'ÐR_ÐauÐwxÓJyÓ?zÓ8{ˆÜ˜CÐ!1Ó2ˆØ@EÒ@Q”Z¤¨¨w¸Ó ;Ô<ÐWYˆ
ß˜d×.×.Ð.ÜÕ]Ó^×^ˆCÜ=GÈÌT×=RÒ=Rœ C§G¡G¨G°RÓ$8Ô9ÐXZˆJßØ!×8Ñ8¸ÀÓL×LˆHØÒ#Ø'×9Ð9¨8¯>©>�
Ü!+¨H×,CÑ,CÓ!D�ß§*ÝEÜ'ÜÕ\Ó]×]óˆNð  ZÐ/Ð/ñ _ñ Mñ ^ùsZ   †A.E$Á5E$ÂE$ÂEÂ>E$ÃE$Ã/E Ã0E$Ä)E$Ä+E$Ä3E$ÅE"ÅE$Å E$Å"E$Nc               ó    € V ^8„  d   QhRRRR/# )r   r}   r   r   zdict | Noner   )r   s   "r   r   rà   ¢  s   € ÷ 
Añ 
A¸sð 
AÈ;ñ 
Ar   c              ƒ  óp   a aaaaaa"  € ^ RI HoHo VVVVV V3R lo\        V3R l4      G Rj  x€L
 #  L5i)z¦``_resolve_gateway_model_context`` for a non-resident session, run off the event loop inside
the profile serving ``source`` (multiplex). Fail-open: None on any error.)Ú_profile_runtime_scopeÚ_resolve_gateway_model_contextc                 ó  <€ \        \        SR R4      RR4      '       d>   S ! SP                  S4      4      ;_uu_ 4        S! S;'       g    RS4      uuRRR4       # S! S;'       g    RS4      #   + '       g   i     L#; i)ÚconfigNÚmultiplex_profilesF)r'   Ú _resolve_profile_home_for_source)rW  rX  r}   r   r  rù   s   €€€€€€r   Ú_resolveÚCGatewayStatusCommandsMixin._resolve_route_context.<locals>._resolve§  sm   ø€ Ü”w˜t X¨tÓ4Ð6JÈE×RÒRÙ+¨D×,QÑ,QÐRXÓ,Y×ZÕZÙ9¸*×:LÐ:LÈÈeÓT÷ [ÒZá1°*×2DÐ2DÀÀeÓLÐL÷ [×Zús   ¿A0Á0B 	c                 ó0   <€ \         P                  ! S 4      # rô   rS  )r]  s   €r   r  ÚCGatewayStatusCommandsMixin._resolve_route_context.<locals>.<lambda>¬  s   ø€ ¤G×$5Ò$5°hÔ$?r   N)rZ   rW  rX  rQ   )r  rù   r}   r   rW  r]  rX  s   ffff@@@r   r  Ú1GatewayStatusCommandsMixin._resolve_route_context¢  s,   þé € ÷ 	W÷	Mò 	Mô
 Ô?Ó@×@Ð@Ñ@ùs   ‰&6¯4°6c               ó    € V ^8„  d   QhRRRR/# rÞ   r   )r   s   "r   r   rà   ®  s   € ÷ 5 ñ 5 °,ð 5 À3ñ 5 r   c              ƒ  óÚ  aa"  € ^ RI Hp ^ RIHoHp \
        P
                  ! 4       pV P                  VP                  4      o\        V R/ 4      ;'       g    / p. p\        V R/ 4      ;'       g    / P                  4        FÁ  w  rxW‚J p	TP                  RTR\        ^ \        V\        VP                  Wt4      4      ,
          4      4      RV	'       d   \        R4      M
\        R	4      R
V	'       d   RM\!        \        VR
R4      ;'       g    R4      RV	'       d   RM\!        \        VRR4      ;'       g    R4      /4       KÃ  	  VP#                  R RR7       \%        VP&                  . 4      p
V
 Uu. uF  q»P                  R4      R8X  g   K  VNK  	  pp\        V R\)        4       4      ;'       g    \)        4        Uu. uF1  p\+        VR4      '       g   K  VP-                  4       '       d   K/  VNK3  	  pp^ RIHp \%        V. 4       Uu. uF  pVP                  R4      R9   g   K  VNK  	  ppVV3R lpV3R lp\        R4      R\        R\3        V4      R7      .pV\5        \7        \9        V^4      4      V4      ,          pVR\        R\3        V4      R7      .,          pV\5        VV4      ,          pVR\        R\3        V4      R7      .,          pV'       d7   VR\        R\3        V4      R7      .,          pV\5        V\:        4      ,          pV'       g-   V'       g%   V'       g   V'       g   VR\        R4      .,          pRP=                  V4      # u upi u upi u upi 5i) z>Handle /agents command - list active agents and running tasks.râ   )Úformat_uptime_shortÚprocess_registryÚ_running_agents_tsrü   rò   ÚelapsedrÉ   zgateway.agents.state_startingzgateway.agents.state_runningré   r   rX   c                ó   € V R ,          # )rg  r   )r¼   s   &r   r  ÚCGatewayStatusCommandsMixin._handle_agents_command.<locals>.<lambda>¿  s   € ¨¨I®r   T)ÚkeyÚreverser¨   ÚrunningÚ_background_tasksÚdone)Úlist_async_delegationsc           
     ó  <€ V w  rVR ,          S8X  d   \        R4      MRpVR,          '       d   RVR,           R2MRpVR,          '       d   RVR,           R2MRpV RVR ,           RVR	,           R
S! VR,          4       V V V 2
.# )rò   zgateway.agents.this_chatr   ré   õ    Â· `r´   rX   z. `r¬   rÉ   r±   rg  r   )Úidx_rowÚidxr¼   ÚcurrentÚsidrX   Úcurrent_session_keyrd  s   &     €€r   Ú
_agent_rowÚEGatewayStatusCommandsMixin._handle_agents_command.<locals>._agent_rowÌ  s«   ø€ Ø‰HˆCØ7:¸=Õ7IÐM`Ô7`”aÐ2Ô3ÐfhˆGØ25°l×2CÔ2C�E˜#˜lÕ+Ð,¨AÑ.ÈˆCØ/2°7¯|¬|�e˜C �L˜>¨Ñ+ÀˆEØ�e˜3˜s =Õ1Ð2°%¸¸G½°~ÀTÙ*¨3¨y­>Ó:Ð;¸C¸5ÀÀÈÀyðRð Sð Sr   c                ó   <€ \        R P                  \        V P                  RR4      4      P	                  4       4      ^Z4      pRV P                  RR4       RS! \        V P                  R^ 4      4      4       RV R	2.# )
r¦   Úcommandr   rª   ré   r©   r¬   Úuptime_secondsrq  r´   )r=   r¹   r   rF   rº   r   )ÚprocÚcmdrd  s   & €r   Ú	_proc_rowÚDGatewayStatusCommandsMixin._handle_agents_command.<locals>._proc_rowÔ  s   ø€ Ü˜Ÿ™¤ T§X¡X¨i¸Ó%<Ó!=×!CÑ!CÓ!EÓFÈÓKˆCØ˜$Ÿ(™( <°Ó5Ð6°eÙ*¬3¨t¯x©xÐ8HÈ!Ó/LÓ+MÓNÐOÈuÐUXÐTYÐYZð\ð ]ð ]r   zgateway.agents.headerzgateway.agents.active_agentsr�   z gateway.agents.running_processeszgateway.agents.async_jobsz%gateway.agents.background_delegationszgateway.agents.nonerø   )rl  r®   Ú
finalizing)rZ   rf   Útools.process_registryrd  re  ÚtimerB  rù   r'   rÓ   rs   rt   r   r1   rF   r   r   Úsortr`   Úlist_sessionsÚsetÚhasattrrn  Útools.async_delegationro  r<   rÚ   rÔ   r»   rÃ   r¹   )r  rß   rf   re  ÚnowÚrunning_startedÚ
agent_rowsrò   rž   ÚpendingÚprocsrõ   Úrunning_processesÚtaskÚbackground_tasksro  r¤   Údelegationsrw  r~  rŸ   rv  rd  s   &&                   @@r   Ú_handle_agents_commandÚ1GatewayStatusCommandsMixin._handle_agents_command®  sø  ùé € å7ßPÜ�iŠi‹kˆØ"×:Ñ:¸5¿<¹<ÓHÐÜ '¨Ð.BÀBÓ G× MÐ MÈ2ˆØ!#ˆ
Ü#*¨4Ð1BÀBÓ#G×#MÐ#MÈ2×"TÑ"TÖ"VÑˆKØÐ6ˆGØ×ÑØ˜{Øœ3˜q¤# c¬E°/×2EÑ2EÀkÓ2WÓ,XÕ&XÓ"YÓZØ¿wœÐ:Ô;ÌAÐNlÓLmØ§G™b´´W¸UÀLÐRTÓ5U×5[Ð5[ÐY[Ó1\ØŸw™¬C´¸¸wÈÓ0K×0QÐ0QÈrÓ,Rðö ñ #Wð 	�‰Ñ6ÀˆÔEÜÐ,×:Ñ:¸BÓ?ˆÙ(-ÓN© 1·±°x³ÀIÑ1MŸQ˜Q©ÐÐNÜ.5°dÐ<OÔQTÓQVÓ.W×.`Ð.`Ô[^Ó[`Ð.`ó JÑ.` TÜ& t¨V×4ô !Ø=A¿Y¹Y¿[÷ !˜DÑ.`Ðð Jõ 	BÜ"-Ð.DÀbÔ"Ió TÑ"I˜QØŸ%™% ›/Ð-RÑR÷ �qÑ"Iˆð Tö	Sõ	]ô
 Ð*Ó+¨R´Ð3QÔY\Ð]gÓYhÔ1iÐjˆØ”œd¤9¨Z¸Ó#;Ó<¸jÓIÕIˆØ�"”aÐ:Ä#ÐFWÓBXÔYÐZÕZˆØ”Ð/°Ó;Õ;ˆØ�"”aÐ3¼3Ð?OÓ;PÔQÐRÕRˆßØ�bœ!ÐCÌ3È{ÓK[Ô\Ð]Õ]ˆEØ”\ +Ô/GÓHÕHˆEß×/×3CÇ{Ø�bœ!Ð1Ó2Ð3Õ3ˆEØ�y‰y˜ÓÐùòE OùòJùòTùsz   „A+M+Á0B M+Ã1M+ÄM+ÄM+Ä6>M+Å4MÆMÆ+M+ÇM!ÇM!Ç2M!Ç8M+ÈM&È+M&È1C-M+ÌM+Ì'M+Ì/M+Ì74M+c               ó    € V ^8„  d   QhRRRR/# rÞ   r   )r   s   "r   r   rà   å  s   € ÷  ñ  °ð  À#ñ  r   c              ƒ  ó$  a"  € ^ RI Ho \        V3R l4      G Rj  x€L
 pVe   VP                  '       g   \	        R4      # \	        R4      .VP
                   Uu. uF+  q3P                  4       P                  R4      '       d   K)  VNK-  	  up,           pVP                  '       d   VRVP                  .,          pVP                  '       d+   VR\	        RVP                  R	7      \	        R
4      .,          pRP                  V4      #  Lìu upi 5i)z³Handle /topup -- show the Nous balance and hand off to the portal. Does NOT charge, confirm,
or track payment (that happens in the browser; the next /topup shows the new balance).©Úbuild_credits_viewc                 ó4   <€ \         P                  ! S R R7      # )T©ÚmarkdownrS  r•  s   €r   r  ÚBGatewayStatusCommandsMixin._handle_topup_command.<locals>.<lambda>é  s   ø€ ¤G×$5Ò$5Ð6HÐSWÕ$Xr   Nzgateway.credits.not_logged_inzgateway.topup.headeru   ðŸ“ˆr   zgateway.topup.portal_link)Úurlzgateway.topup.hintrø   )Úagent.account_usager–  rQ   Ú	logged_inr   Úbalance_linesÚlstripÚ
startswithÚidentity_lineÚ	topup_urlr¹   )r  rß   ÚviewÚlnrŸ   r–  s   &&   @r   Ú_handle_topup_commandÚ0GatewayStatusCommandsMixin._handle_topup_commandå  sÛ   øé € õ 	;ÜÔXÓY×YˆØŠ<˜tŸ~Ÿ~˜~ÜÐ4Ó5Ð5äÐ)Ó*Ð+¸D×<NÒ<NÓ.uÑ<N°b×V_ÑV_ÓVa×VlÑVlÐms×Vt¯r¨rÑ<NÑ.uÕuˆØ××ÐØ�b˜$×,Ñ,Ð-Õ-ˆEØ�>�>ˆ>Ø�bœ!Ð7¸T¿^¹^ÔLÌaÐPdÓNeÐfÕfˆEØ�y‰y˜ÓÐñ Zùò /vùs8   ƒDœD	�D·$DÁ&DÂDÂDÂ'&DÃ<DÄDc               ó    € V ^8„  d   QhRRRR/# )r   rH  Úboolr   r‚   r   )r   s   "r   r   rà   ô  s   € ÷ ñ Àð Èñ r   c                ó¦  aaa	a
€  ^ RI HoHp  V P                  SV4      pTP                  R4      '       g   . '       g   . # T'       d   \        TT3R lR. R. /4      MRp^ RIH	o	H
o
 \        TT	T
3R l. 4      pT! YVR	R
7      T'       d   R.T,           ,           # . ,           #   \         d    \        4       .u # i ; i  \         d    . u # i ; i)z�/context per-category block (plain text, chars/4 estimate, same engine as /usage).
Runs in a thread; returns [] and never raises.)Úcompute_context_detailsÚrender_context_breakdown_linesÚ
categoriesc                 ó   <€ S! S 4      # rô   r   )rž   rª  s   €€r   r  ÚEGatewayStatusCommandsMixin._context_breakdown_block.<locals>.<lambda>ÿ  s   ø€ Ñ*AÀ%Ô*Hr   ÚskillsÚtoolsetsN)Úcontext_file_sources_for_agentÚrender_context_file_linesc                 ó    <€ S! S! S 4      4      # rô   r   )rž   r±  r²  s   €€€r   r  r®    s   ø€ Ñ-FÑGeÐfkÓGlÔ-mr   F)r>  Úgridr   )r�   rª  r«  Ú_session_context_breakdownr
   rT   rF   r`   Úagent.context_file_sourcesr±  r²  rM   )r  rž   rù   rH  r«  Úpayloadr>  Ú
file_linesrª  r±  r²  s   &f&&    @@@r   rF  Ú3GatewayStatusCommandsMixin._context_breakdown_blockô  sÔ   û€ ð	ßgð.Ø×9Ñ9¸%ÀÓH�ð —K‘K ×-Ò-·Ø�	ßmu”kÕ"HÈ8ÐUWÐYcÐegÐJhÔiÐ{ˆGßlÜ$Ö%mÐoqÓrˆJÙ1°'ÐQVÔW×pzÐ\^Ð[_ÐblÕ[lõ  Dð  Dð  ACõ  Dð  Døô 'ô .Ü*Ó,Ð-Ò-ð.ûô ô 	ØŠIð	úsQ   †C  �B$ ¡C  ¸C  Á C  ÁC  Á
AC  ÂC  Â$B=Â:C  Â<B=Â=C  Ã CÃCc               ó   € V ^8„  d   QhRR/# )r   r   r[   r   )r   s   "r   r   rà     s   € ÷ Añ A¸4ñ Ar   c                óÜ   € ^ RI Hp V P                  p VP                  VP	                  V4      P
                  4      ;'       g    . pT! Y4      #   \         d    h \         d    . p L"i ; i)z®Per-category context estimate (chars/4) for *agent* over the session transcript (sync).
Raises ``TranscriptReadError`` (unreadable rows must not pass as an empty transcript).)Ú!compute_session_context_breakdown)r�   r¼  Úsession_storerG  rû   ré   r
   rM   )r  rž   rù   r¼  ÚstorerG   s   &&&   r   rµ  Ú5GatewayStatusCommandsMixin._session_context_breakdown  sp   € õ 	NØ×"Ñ"ˆð	Ø×+Ñ+¨E×,GÑ,GÈÓ,O×,ZÑ,ZÓ[×aÐaÐ_aˆGñ
 1°Ó@Ð@øô	 #ô 	ØÜô 	ØŠGð	ús   ”0A ÁA ÁA+Á%A+Á*A+c               ó   € V ^8„  d   QhRR/# rÅ   r   )r   s   "r   r   rà     s   € ÷ ñ ¸ñ r   c           
     ó*  €   V P                  W4      pTP                  R4      ;'       g    . pT'       g   . # TP                  R4      ;'       g    ^ p\	        R4      .pT Fì  p\        TP                  R4      ;'       g    ^ 4      pT^ 8:  d   K0  \        TP                  R4      ;'       g    R4      p	\	        RT	 24      p
T
P                  RT	 24      '       d%   \        TP                  R	4      ;'       g    T	4      p
T'       d   \        Y…,          ^d,          4      M^ pTP                  \	        R
T
\        T4      RT 2R7      4       Kî  	  \        T4      ^8”  d   T# . #   \         d    \        4       .u # i ; i  \         d    . u # i ; i)zV/usage per-category context breakdown (chars/4 estimate). Returns [] and never raises.r¬  Úestimated_totalzgateway.usage.breakdown_headerrç   Úidr   zgateway.usage.breakdown_cat_Úbreakdown_cat_Úlabelzgateway.usage.breakdown_liner‡   )rÅ  r�   rÌ   )rµ  r
   rT   rF   r   r   r   Úendswithr  rs   r/   r<   rM   )r  rž   rù   r·  r¬  r6   ÚoutÚcatrç   Úcat_idrÅ  rÌ   s   &&&         r   Ú_context_breakdown_linesÚ3GatewayStatusCommandsMixin._context_breakdown_lines  st  € ð	ð.Ø×9Ñ9¸%ÓH�ð !Ÿ™ \Ó2×8Ð8°bˆJßØ�	Ø—K‘KÐ 1Ó2×7Ð7°aˆEÜÐ5Ó6Ð7ˆCÛ!�Ü˜SŸW™W XÓ.×3Ð3°!Ó4�Ø˜Q”;ÙÜ˜SŸW™W T›]×0Ð0¨bÓ1�ÜÐ8¸¸ÐAÓB�Ø—>‘> N°6°(Ð";×<Ò<Ü §¡¨Ó 0× :Ð :°FÓ;�Eß5:”e˜F�N¨SÕ0Ô1À�Ø—
‘
œ1Ð;À5ÔPTÐU[ÓP\ÐdeÐfiÐejÐbkÔlÖmñ "ô ˜c›( Qœ,�3Ð.¨BÐ.øô# 'ô .Ü*Ó,Ð-Ò-ð.ûô$ ô 	ØŠIð	úsc   ƒE& ”F ¬
F ·F ¹F Á0F Â,F Â/AF Ã;F Ä
AF Å$F Å&E?Å<F Å>E?Å?F ÆFÆFc               ó    € V ^8„  d   QhRRRR/# rÞ   r   )r   s   "r   r   rà   -  s   € ÷ Z*ñ Z*°ð Z*À#ñ Z*r   c           
   ƒ  ó¬  aaaaaaaa"  € VP                   pV P                  V4      pVP                  4       P                  4       pV'       d.   VP	                  4        Uu. uF  qUP                  4       NK  	  upM. p\        V4      ;'       d    V^ ,          R8H  pV'       d   V'       g   \        RVR7      # V P                  V4      oV3R lR 4       w  oooS'       g,   \        V RR4      e   V P                  V4      G Rj  x€L
 w  ooS'       g   \        R 4      G Rj  x€L
 ;'       g    RoV'       d€   \        S;'       g    R4      P                  4       P                  4       R	8w  d   \        R
4      # ^ RIHp \        P                   ! VSSRVR,          9   R7      G Rj  x€L
 p	V	P"                  # S;'       d    \        VVV3R l4      G Rj  x€L
 p
V
'       d   \%        V
RR7      M. o^ RIHo S'       d   \        SRR4      MRo\        VV3R l. 4      G Rj  x€L
 o^ RIHp S Uu. uF
  qË! V4      NK  	  upoR VV3R llpS'       dz   \-        SR4      '       dh   SP.                  ^ 8”  dW   \1        S4      p\        P                   ! V P2                  SV4      G Rj  x€L
 pV'       d   VR.V,           ,          pV! V4      # V P4                  P7                  V4      G Rj  x€L
 p V P4                  P9                  VP:                  4      G Rj  x€L
 pT'       dL   \A        T4      w  ppT! \        R4      \        RTR7      \        R\C        T4      R7      \        R4      .4      # S'       g	   S'       d	   T! . 4      # \        R4      # u upi  EL™ EL} ELû ELÏ EL…u upi  EL LÄ L˜  \<         d    \?        4       u # i ; i5i) z§Handle /usage -- token usage for the current session (live or cached agent) plus
account/credit blocks; ``/usage reset [--force]`` redeems a banked Codex reset credit.Úresetz gateway.usage.unknown_subcommand)Úargsc              3  óR   <"  € T F  pS'       d   \        SVR 4      MR x € K  	  R # 5irô   r&   )ro   r"  rž   s   & €r   rq   ÚCGatewayStatusCommandsMixin._handle_usage_command.<locals>.<genexpr>=  s%   øé € ð '
Ù@c¸1§uŒG�E˜1˜dÔ#°$Ô6Ó@cùs   ƒ'�'r+  Nc                 ó6   € \         P                  ! \        4      # rô   )rD  rE  r^   r   r   r   r  ÚBGatewayStatusCommandsMixin._handle_usage_command.<locals>.<lambda>F  s   € ¬G×,=Ò,=Ô>RÔ,Sr   r   zopenai-codexz"gateway.usage.reset_wrong_provider)Úredeem_codex_reset_creditz--force:é   NN)rh   ri   Úforcec                 ó@   <€ \         P                  ! \        SSS R 7      # ))rh   ri   )rD  rE  r   )ri   rh   rY   s   €€€r   r  rÓ  S  s   ø€ ”G×%Ò%Ô&9¸8ÈhÐ`gÕhr   Tr˜  )Únous_credits_linesÚ_credits_statec                 ó6   <€ \         P                  ! SR S R7      # )T)r™  Úcredits_staterS  )rÛ  rØ  s   €€r   r  rÓ  _  s   ø€ ”G×%Ò%Ð&8À4ÐWdÕer   )Úportal_wordingc               ó    € V ^8„  d   QhRRRR/# )r   rŸ   r‚   r   r   r   )r   s   "r   r   ÚFGatewayStatusCommandsMixin._handle_usage_command.<locals>.__annotate__f  s   € ÷ 	$ñ 	$¨	ð 	$°cñ 	$r   c                ó¤   <€ SS3 F7  pV'       g   K  V '       d   V P                  R 4       V P                  V4       K9  	  RP                  V 4      # )r   rø   )rs   r×   r¹   )rŸ   ÚblockÚaccount_linesÚcredits_liness   & €€r   Ú_with_account_blocksÚNGatewayStatusCommandsMixin._handle_usage_command.<locals>._with_account_blocksf  sC   ø€ à'¨Ó7�ß‘5ßØŸ™ RÔ(Ø—L‘L Ö'ñ	 8ð
 —9‘9˜UÓ#Ð#r   r›   z!gateway.usage.header_session_infozgateway.usage.label_messagesr�   z%gateway.usage.label_estimated_contextz"gateway.usage.detailed_after_firstzgateway.usage.no_data)rY   rh   ri   )"rù   rB  r?  r   rº   r@  r¨  r   rA  r'   Ú_persisted_billing_routerQ   r   rœ  rÔ  rD  rE  Úmessager   rØ  Úagent.plan_limitsrÜ  r†  r“   rÑ   rÊ  rú   rû   rG  ré   r
   rT   rJ   r/   )r  rß   rù   rò   Úraw_argsÚarÏ  Úwants_resetrÔ  ÚresultÚaccount_snapshotrÜ  Úlinerã  rŸ   Úbreakdown_linesrw   rG   rK  r�   rá  rž   ri   rh   râ  rÛ  rØ  rY   s   &&                  @@@@@@@@r   Ú_handle_usage_commandÚ0GatewayStatusCommandsMixin._handle_usage_command-  s\  ÿé € ð —‘ˆØ×2Ñ2°6Ó:ˆØ×)Ñ)Ó+×1Ñ1Ó3ˆß8@ 8§>¡>Ô#3Ó4Ñ#3˜a—‘–	Ñ#3Ò4ÀbˆÜ˜4“j×7Ð7 T¨!¥W°Ñ%7ˆßŸÜÐ7¸hÔGÐGð ×(Ñ(¨Ó5ˆô'
Ù@có'
Ñ#ˆ�(˜G÷ œG D¨-¸Ó>ÒJØ'+×'DÑ'DÀVÓ'L×!LÑˆH�hßô $Ñ$SÓT×T×\Ð\ÐX\ˆHßÜ�8—>�>˜rÓ"×(Ñ(Ó*×0Ñ0Ó2°nÔDÜÐ=Ó>Ð>ÝEÜ"×,Ò,Ø)°HÀgÐU^ÐbfÐgiÕbjÑUjô÷ ˆFð —>‘>Ð!ð $÷ 
ð 
¬fÞhó/
÷ )
Ð÷ L\Ô&Ð'7À$ÕGÐacð 	õ 	;ßBGœ Ð'7¸Ô>ÈTˆÜ$ÝeØó
÷ 
ˆõ
 	5Ù:GÓH¹-°$˜¨Ö-¹-ÑHˆ÷	$ñ 	$÷ ”W˜UÐ$:×;Ò;À×@WÑ@WÐZ[Ô@[Ü,¨UÓ3ˆEô %,×$5Ò$5°d×6SÑ6SÐUZÐ\bÓ$c×cˆOßØ˜"˜ Õ/Õ/�Ù'¨Ó.Ð.ð #×6Ñ6×LÑLÈVÓT×Tˆð	(Ø ×4Ñ4×DÑDÀ]×E]ÑE]Ó^×^ˆG÷ Ü0°Ó9‰MˆF�EÙ'ÜÐ5Ó6ÜÐ0¸Ô>ÜÐ9ÄÀfÃÔNÜÐ6Ó7ð	)ó ð ÷ ŸMÙ'¨Ó+Ð+ÜÐ(Ó)Ð)ùòi 5ò "Mò
 Uò
ò)
ò
ùò Iò dñ Uá^øÜ"ô 	(Ü%Ó'Ò'ð	(üs*  ŠAOÁ NÁ8OÂOÂ$OÂ,AOÄNÄOÄOÄ$N!Ä%
OÄ0
OÄ;OÅ	A OÆ)N$Æ*OÇOÇN'ÇOÇ%OÈ#OÈ%N*È&OÈ4N-ÉOÉAOÊ,N2Ê-OÊ97OË0N5Ë1OË6(N9 ÌN7ÌN9 Ì#OÌ+AOÍ>OÎOÎ!OÎ$OÎ'OÎ*OÎ-OÎ5OÎ7N9 Î9OÏOÏOÏOc              ƒ  óÊ   a a"  € V V3R lp\        V/ / 34      G Rj  x€L
 w  r4VP                  R4      '       d   TMTpVP                  R4      VP                  R4      3#  LC5i)z^``(provider, base_url)`` from the SessionDB row / most recent route when no agent is resident.c               “  ó`  <"  € SP                   P                  S4      G R j  x€L
 p SP                  P                  V P                  4      G R j  x€L
 ;'       g    / pSP                  P                  V P                  4      G R j  x€L
 pT\        V\        4      '       d   V3# / 3#  L… LZ L%5irô   )rú   rû   r+  r   ré   r%  r   r[   )ÚentryÚ	persistedr   r  rù   s      €€r   Ú_rowsÚBGatewayStatusCommandsMixin._persisted_billing_route.<locals>._rows‹  s‘   øé € Ø×2Ñ2×HÑHÈÓP×PˆEØ"×.Ñ.×:Ñ:¸5×;KÑ;KÓL×L×RÐRÐPRˆIØ×*Ñ*×IÑIÈ%×JZÑJZÓ[×[ˆEØ¤z°%¼×'>Ò'>˜eÐFÐFÀBÐFÐFñ QÙLÙ[ùs9   ƒB.¢B(£,B.ÁB*Á
B.Á+B.ÂB,Â"B.Â*B.Â,B.Nrm   Úbilling_base_url)rQ   rF   )r  rù   rõ  rô  Úrecentr¼   s   ff    r   rå  Ú3GatewayStatusCommandsMixin._persisted_billing_route‰  s^   ùé € ö	Gô
 #)¨°°R°Ó"9×9Ñˆ	ØŸ
™
Ð#5×6Ò6‰f¸IˆØ�w‰wÐ)Ó*¨C¯G©GÐ4FÓ,GÐGÐGñ :ùs   „A#�A!žAA#c               ó    € V ^8„  d   QhRRRR/# rÞ   r   )r   s   "r   r   rà   ”  s   € ÷ '8ñ '8°Lð '8ÀSñ '8r   c              ƒ  ó  a	a
aa"  € \         P                  ! RRVP                  4       P                  4       4      p^RuooVP	                  4       p^ pV\        V4      8  d˜   W4,          V^,           \        V4      8  d   W4^,           ,          MRreVR8X  d   Ve    \        V4      oT^,          pKa  VR8X  d   Ve   Wd^,           uopKy  VP                  4       '       d   \        V4      MSoV^,          pK§   ^ RI
Ho
 ^ R	IHo	 V	V
VV3R
 lpV P                  V4      G Rj  x€L
 #   \         d    \        RTR7      u # i ; i L"  \         d0   p\         P#                  RTRR7       \        RTR7      u Rp?# Rp?ii ; i5i)zMHandle /insights [N | --days N] [--source S] -- usage insights and analytics.z'[\u2012\u2013\u2014\u2015](days|source)z--\1Nz--dayszgateway.insights.invalid_daysr   z--source)Úacquire)ÚInsightsEnginec                 óª   <€ S! 4       p  S! V 4      pVP                  VP                  SSR 7      4      ^ RIHp V! V 4       #   ^ RIHp T! T 4       i ; i))Údaysrù   )Úrelease_or_close)Úformat_gatewayÚgenerateÚhermes_state_registryr   )r  Úenginer   rý  rü  rÿ  rù   s      €€€€r   Ú_run_insightsÚJGatewayStatusCommandsMixin._handle_insights_command.<locals>._run_insights¬  sP   ø€ Ù“Y�ð)Ù+¨BÓ/�FØ!×0Ñ0°·±ÀdÐSY°Ó1ZÓ[åFÙ$ RÕ(øõ GÙ$ RÕ(ús   Š)A ÁAzInsights command error: %sT)Úexc_infozgateway.insights.error)Úerror)ÚreÚsubr?  r   rº   r<   r   r    r   Úisdigitr  rü  Úagent.insightsrý  Ú_run_in_executor_with_contextrM   Úloggerr  )r  rß   rÏ  Úpartsr¾   Úflagr   r  Úerý  rü  rÿ  rù   s   &&       @@@@r   Ú_handle_insights_commandÚ3GatewayStatusCommandsMixin._handle_insights_command”  sT  ûé € ô �vŠvÐ@À'È5×KaÑKaÓKc×KiÑKiÓKkÓlˆØ˜4ˆˆˆfØ—
‘
“ˆØˆØ”#�e“*ŒnØ�(°A¸µE¼CÀ»JÔ4F E¨a­%¦LÈD�%Ø�xÔ EÒ$5ðKÜ˜u›:�Dð �Q•’Ø˜Ô#¨Ò(9Ø! q¥5�	�šà$(§L¡L§N¢N”s˜4”y¸�Ø�Q•’ð	8Ý5Ý5÷)ð )ð ×;Ñ;¸MÓJ×JÐJøô1 "ô KÜÐ<ÀEÔJÒJðKúñ0 KøÜô 	8Ü�L‰LÐ5°qÀ4ˆLÔHÜÐ-°QÔ7Õ7ûð	8üsr   †BFÂD( Â(8FÃ!FÃ:)E Ä#EÄ$E Ä'FÄ(EÅ FÅEÅFÅE ÅFÅ$E=Å7FÅ8FÅ=FÆFr   rô   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r  r   Ústaticmethodr  rL  rC  r  r‘  r¥  rF  rµ  rÊ  rï  rå  r  Ú__static_attributes__r   r   r   rÜ   rÜ   ï   si   † ÙjõK õZ]ð& ô"ó ð"õ
3òj0÷*
Aõ5 õn õõ$Aõõ4Z*òx	H÷'8ñ '8r   rÜ   rô   )-r  Ú
__future__r   ÚloggingrD  r1  r
  r	  r‚  Útypingr   rœ  r   r   Ú
agent.i18nr   Úgateway.configr   Úgateway.platforms.eventr	   Úgateway.session_transcriptr
   Úhermes_cli.status_reportr   Ú	getLoggerr  rÖ   r   r!   r)   r/   r7   r=   rJ   rQ   ÚHISTORY_UNREADABLErT   r^   r`   r€   r¢   rÃ   rÑ   rÚ   rÜ   r   r   r   Ú<module>r%     s¸   ðñGõ #ã Û Û Û 	Û 	Û Ý ç OÝ Ý #Ý 0Ý :Ý 8ð 
×	Ò	˜=Ó	)€à€	õMõ
õ&õõ8õDõ;ôð(Ð õ
2õXôõ*hõZõBõ2õ8÷L8ó L8r   