+
    –°³j©  ã                   ó>  a € R t0 t R 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 ]P                  ! ]4      tRt^t ! R R]	RR	7      t ! R
 R]	4      tR. R/ /t] ^ k Rs] ^k 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# ) u®  Detect whether the process is being invoked by an AI coding agent.

Detection is based on environment variables that AI agents set in their shell
sessions. `AI_AGENT` and `AGENT` are treated as a universal standard (any
tool can set its harness id there); the remaining checks are tool-specific and
ordered by priority (first match wins).

The list of known harnesses is maintained on the Hub and exposed at
`{ENDPOINT}/api/agent-harnesses`. We fetch it at most once a day and cache it
locally so the list can be updated without requiring a new client release.

Detection is entirely best-effort: there is no hardcoded list of harnesses. When
the registry cannot be fetched (and no cached copy is available), detection simply
reports "no agent". Any error while fetching/reading the registry is swallowed â€”
detection must never make a process fail.

More details: https://huggingface.co/docs/hub/agents-overview#register-your-agent-harness
N)ÚPath)ÚOptionalÚ	TypedDict)Ú	constants)Úloggingc                   ó0   a € ] tR t^4t o RtV 3R ltRtV tR# )ÚHarnessInfozbA single harness entry. `envVars` maps an env var name to a match pattern (see `_env_vars_match`).c                ó<   <€ V ^8„  d   Qh/ S[ S[S[3,          ;R&   # )é   ÚenvVars)ÚdictÚstr)ÚformatÚ__classdict__s   "€Úd/home/luca/screen-checking/.venv/lib/python3.14/site-packages/huggingface_hub/utils/_detect_agent.pyÚ__annotate__ÚHarnessInfo.__annotate__4   s   ø‡ ‚ ñ ‘#‘s�(�^Ñò ó    © N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r   s   @r   r   r   4   s   ø‡ € Ùl÷ ƒ r   r   F)Útotalc                   ó0   a € ] tR t^:t o RtV 3R ltRtV tR# )ÚRegistryzJThe agent harness registry, as served by `{ENDPOINT}/api/agent-harnesses`.c                óX   <€ V ^8„  d   Qh/ S[ S[,          ;R&   S[S[S[3,          ;R&   # )r
   ÚstandardEnvVarsÚ	harnesses)Úlistr   r   r   )r   r   s   "€r   r   ÚRegistry.__annotate__:   s-   ø‡ ‚ ñ ™#•YÑñ ñ ‘C™Ð$Õ%Ñ%ò	 r   r   Nr   r   s   @r   r!   r!   :   s   ø‡ € ÙT÷ ƒ r   r!   r#   r$   c                ó:   € V ^8„  d   QhR\         \        ,          /# ©r
   Úreturn)r   r   )r   s   "r   r   r   I   s   € ÷ ñ ”hœs•mñ r   c                 óÂ  € \        4       p V P                  R4      ;'       g    . pV P                  R4      ;'       g    / pVP                  4        F  w  r4T;'       g    / P                  R4      pV'       d   \        V4      '       d   Vu # V F<  p\        P
                  P                  VR4      P                  4       V8X  g   K8  Vu u # 	  K�  	  VP                  4        Uu0 uF  qwP                  4       kK  	  ppV FT  p\        P
                  P                  VR4      P                  4       P                  4       ;p	'       g   KI  W˜9   d   V	u #  R# 	  R# u upi )aG  Return the id of the detected AI agent harness or `None`.

Harnesses are checked in registry order; for each one we match its env var
pattern(s) and, failing that, the standard `AI_AGENT` / `AGENT` vars
against the harness id. The first match wins. When a standard var is set to
an unrecognized value, `"unknown"` is returned.
r#   r$   r   Ú ÚunknownN)	Ú_get_registryÚgetÚitemsÚ_env_vars_matchÚosÚenvironÚstripÚkeysÚlower)
ÚregistryÚstandard_varsr$   Ú
harness_idÚinfoÚenv_varsÚvarÚkÚlowercased_harnessesÚvalues
             r   Údetect_agentr?   I   s  € ô ‹€HØ—L‘LÐ!2Ó3×9Ð9°r€MØ—‘˜[Ó)×/Ð/¨R€Ià%ŸO™OÖ-Ñˆ
Ø—J�J˜B×#Ñ# IÓ.ˆßœ¨×1Ò1ØÒÛ ˆCÜ�z‰z�~‰~˜c 2Ó&×,Ñ,Ó.°*Ö<Ø!Ô!ó !ñ	 .ð 09¯~©~Ô/?Ó@Ñ/?¨!ŸG™GžIÑ/?ÐÐ@ÛˆÜ—J‘J—N‘N 3¨Ó+×1Ñ1Ó3×9Ñ9Ó;Ð;ˆ5×;Ð;ØÔ,Ø’Úñ	 ñ ùò As   Ã&Ec                ó$   € V ^8„  d   QhR\         /# r(   )Úbool)r   s   "r   r   r   h   s   € ÷ &ñ &”$ñ &r   c                 ó   € \        4       RJ# )zDReturn `True` if the process is being invoked by an AI coding agent.N)r?   r   r   r   Úis_agentrC   h   s   € ä‹> Ð%Ð%r   c                óR   € V ^8„  d   QhR\         \        \        3,          R\        /# )r
   r:   r)   )r   r   rA   )r   s   "r   r   r   m   s"   € ÷ ñ œd¤3¬ 8�nð ´ñ r   c                ó°   € V P                  4        FA  w  r\        P                  P                  V4      pV'       g   K.  VR8X  d    R# W28X  g   K@   R# 	  R# )zÑReturn `True` if any `(var, pattern)` from the harness matches the environment.

Supported patterns:
  - `"*"`: the variable is set to any non-empty value
  - `"<value>"`: the variable equals this exact value
Ú*TF)r/   r1   r2   r.   )r:   r;   Úpatternr>   s   &   r   r0   r0   m   sG   € ð !Ÿ™Ö(‰ˆÜ—
‘
—‘˜sÓ#ˆßÙØ�cŒ>ÚØÖÚñ )ñ r   c                ó$   € V ^8„  d   QhR\         /# r(   ©r!   )r   s   "r   r   r      s   € ÷ ñ ”xñ r   c                 ó¦   € \         f    \        4       s \         # \         #   \         d&    \        P	                  RRR7       \
        s  \         # i ; i)z©Return the harness registry, loading (and caching in-process) on first call.

Best-effort: any unexpected error degrades to an empty registry so detection
never raises.
z+Could not resolve agent harnesses registry.T©Úexc_info)Ú	_registryÚ_load_registryÚ	ExceptionÚloggerÚdebugÚ_EMPTY_REGISTRYr   r   r   r-   r-      sR   € ô Òð	(Ü&Ó(ˆIô ÐŒ9Ðøô ô 	(Ü�L‰LÐFÐQUˆLÔVÜ'‰IÜÐð	(ús   Š
   (AÁAc                ó$   € V ^8„  d   QhR\         /# r(   rI   )r   s   "r   r   r   �   s   € ÷ ñ œñ r   c                 óÈ   € \         P                  p \        V \        R7      ;p'       d   V# \	        4       ;pe   \        W4       V# \        V RR7      ;p'       d   V# \        # )zºResolve the registry from the local cache or the Hub.

No hardcoded list: if the Hub is unreachable and no cached copy exists, an
empty registry is returned (i.e. no agent is detected).
)Úmax_ageN)r   ÚAGENT_HARNESSES_PATHÚ_read_cached_registryÚ_REGISTRY_TTL_SECONDSÚ_fetch_registryÚ_write_cached_registryrR   )ÚpathÚcachedÚfetchedÚstales       r   rN   rN   �   se   € ô ×)Ñ)€Dô ' tÔ5JÔKÐK€vÖKØˆô #Ó$Ð$ˆÒ1Ü˜tÔ-Øˆô & d°DÔ9Ð9€uÖ9ØˆÜÐr   c                óX   € V ^8„  d   QhR\         R\        R,          R\        R,          /# )r
   r[   rU   Nr)   )r   Úintr!   )r   s   "r   r   r   ¦   s)   € ÷ ñ ¤ð ¬c°D­jð ¼XÈ½_ñ r   c                óÀ  €  \         P                  P                  V 4      '       g   R# VeA   \        P                  ! 4       \         P                  P	                  V 4      ,
          V8¼  d   R# \        V RR7      ;_uu_ 4       p\        P                  ! V4      uuRRR4       #   + '       g   i     R# ; i  \         d    \        P                  RRR7        R# i ; i)zBReturn the cached registry, or `None` if missing/stale/unreadable.Núutf-8©Úencodingz/Could not read cached agent harnesses registry.TrK   )r1   r[   ÚexistsÚtimeÚgetmtimeÚopenÚjsonÚloadrO   rP   rQ   )r[   rU   Úfs   && r   rW   rW   ¦   s“   € ð	Ü�w‰w�~‰~˜d×#Ò#ÙØÒ¤D§I¢I£K´"·'±'×2BÑ2BÀ4Ó2HÕ$HÈWÔ#TÙÜ�$ ×)Õ)¨QÜ—9’9˜Q“<÷ *×)×)Ó)ûäô Ü�‰ÐFÐQUˆÔVÚðús;   ‚$B7 ©AB7 Á-B7 ÂB#Â
B7 Â#B4	Â.B7 Â4B7 Â7"CÃCc                ó4   € V ^8„  d   QhR\         R\        RR/# )r
   r[   r6   r)   N)r   r!   )r   s   "r   r   r   ´   s&   € ÷ Qñ Q¤ð Q´ð Q¸Tñ Qr   c                 ó8  €  \        V 4      P                  P                  R R R7       \        V RRR7      ;_uu_ 4       p\        P
                  ! W4       RRR4       R#   + '       g   i     R# ; i  \         d    \        P                  RR R7        R# i ; i)T)ÚparentsÚexist_okÚwrb   rc   Nz)Could not cache agent harnesses registry.rK   )	r   ÚparentÚmkdirrh   ri   ÚdumprO   rP   rQ   )r[   r6   rk   s   && r   rZ   rZ   ´   sr   € ðQÜˆT‹
×Ñ×Ñ¨°tÐÔ<Ü�$˜ g×.Õ.°!Ü�IŠI�hÔ"÷ /×.×.Ò.ûäô QÜ�‰Ð@È4ˆ×PðQús.   ‚<A3 ¾AÁA3 ÁA0	Á*A3 Á0A3 Á3"BÂBc                ó2   € V ^8„  d   QhR\         R,          /# )r
   r)   NrI   )r   s   "r   r   r   ½   s   € ÷ ñ œ D�ñ r   c                 ó,  € \         P                  '       d   R#  ^RIHp  V ! 4       P	                  \         P
                   R2\        R7      pVP                  4        VP                  4       #   \         d    \        P                  RRR7        R# i ; i)zMFetch the registry from the Hub. Returns `None` when offline or on any error.N)Úget_sessionz/api/agent-harnesses)Útimeoutz6Could not fetch agent harnesses registry from the Hub.TrK   )r   ÚHF_HUB_OFFLINEÚ_httprv   r.   ÚENDPOINTÚ_REGISTRY_FETCH_TIMEOUTÚraise_for_statusri   rO   rP   rQ   )rv   Úresponses     r   rY   rY   ½   sƒ   € ä××ÐÙðÝ&á“=×$Ñ$Ü×!Ñ!Ð"Ð"6Ð7Ü+ð %ó 
ˆð 	×!Ñ!Ô#Ø�}‰}‹ÐøÜô Ü�‰ÐMÐX\ˆÔ]Úðús   šAA- Á-"BÂBc                óv   € V ^8„  d   Qh/ ^ \         9   d
   \        ;R&   ^\         9   d   \        R,          ;R&   # )r
   rR   NrM   )Ú__conditional_annotations__r!   )r   s   "r   r   r      s9   € ÷ ñ ÷j EÒ D”Ñ Dñk÷p "Ò !Œ8�d�?Ñ !òqr   i€Q )r   r   ri   r1   rf   Úpathlibr   Útypingr   r   r+   r   r   Ú
get_loggerr   rP   rX   r{   r   r!   rR   rM   r?   rC   r0   r-   rN   rW   rZ   rY   r   )r   s   @r   Ú<module>rƒ      s¤   øðöó& Û 	Û Ý ß &å Ý ð 
×	Ò	˜HÓ	%€ð "Ð ð Ð ô�) 5õ ô&ˆyô &ð /°°KÀÐD€Ó Dð "€	Ó !õõ>&õ
õ$õ õ.õQ÷r   