§
    øžyjJ	  ã                  ó    — U d Z ddlmZ ddlmZ  ee¦  «                             ¦   «         j        j        Zda	de
d<   dd„Zdd
„Zdd„Zdd„ZdS )up  Detect when the gateway is running stale code after a hot ``git pull``.

The gateway is a single long-lived process; its ``sys.modules`` is frozen at
boot. If the checkout is updated underneath it (a manual ``git pull``, or the
window before ``hermes update``'s graceful restart fires), a first-time lazy
import on a new code path can resolve a freshly-pulled consumer module against a
stale cached dependency -> ImportError (see
``tests/test_stale_utils_module_import.py`` for the exact failure).

We snapshot the checkout revision at gateway startup and compare on demand, so
risky callers (e.g. ``/model`` switching) can refuse with a clear "restart the
gateway" message instead of crashing on a cryptic import error.

If the revision can't be read (non-git install, IO error), the boot snapshot
stays ``None`` and skew detection no-ops â€” it never produces a false positive.
é    )Úannotations)ÚPathNú
str | NoneÚ_boot_fingerprintÚreturnc                 óR   — 	 ddl m}   | t          ¦  «        S # t          $ r Y dS w xY w)zþCurrent checkout fingerprint, reusing the CLI's git-rev reader.

    ``hermes_cli.main`` is always already imported in a gateway process (it's
    the entry point), so this import is free and avoids duplicating the
    worktree-aware ref resolution.
    r   ©Ú_read_git_revision_fingerprintN)Úhermes_cli.mainr
   Ú_PROJECT_ROOTÚ	Exceptionr	   s    ú7/home/ragecks/.hermes/hermes-agent/gateway/code_skew.pyÚ_fingerprintr      sL   € ðØBÐBÐBÐBÐBÐBà-Ð-­mÑ<Ô<Ð<øÝð ð ð Øˆtˆtðøøøs   ‚ ˜
&¥&ÚNonec                 ó4   — t           €t          ¦   «         a dS dS )z?Snapshot the checkout revision at gateway startup (idempotent).N)r   r   © ó    r   Úrecord_boot_fingerprintr   )   s"   € õ Ð Ý(™NœNÐÐÐð !Ð r   ÚfingerprintÚstrc                óŒ   — |                       dd¦  «        d         }|r#|dk    rt          |¦  «        dk    r
|dd…         S |p| S )z<Render a ``git:<ref>:<sha>`` fingerprint as a compact label.ú:é   éÿÿÿÿÚ
unresolvedé
   N)ÚrsplitÚlen)r   Úshas     r   Ú_shortr    0   sT   € à
×
Ò
˜S !Ñ
$Ô
$ RÔ
(€CØ
ð ˆs�lÒ"Ð"¥s¨3¡x¤x°"¢} }Ø�3�B�3ŒxˆØÐ�+Ðr   útuple[str, str] | Nonec                 ó”   — t           €dS t          ¦   «         } | �| t           k    rdS t          t           ¦  «        t          | ¦  «        fS )zcReturn ``(boot_rev, disk_rev)`` short labels if the checkout drifted
    since boot, else ``None``.N)r   r   r    )Úcurrents    r   Údetect_code_skewr$   8   sG   € õ Ð ØˆtÝ‰nŒn€GØ€˜'Õ%6Ò6Ð6ØˆtÝÕ#Ñ$Ô$¥f¨W¡o¤oÐ5Ð5r   )r   r   )r   r   )r   r   r   r   )r   r!   )Ú__doc__Ú
__future__r   Úpathlibr   Ú__file__ÚresolveÚparentr   r   Ú__annotations__r   r   r    r$   r   r   r   ú<module>r,      sÅ   ððð ð ð" #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à��X‘”×&Ò&Ñ(Ô(Ô/Ô6€Ø $Ð Ð $Ð $Ð $Ñ $ðð ð ð ð+ð +ð +ð +ðð ð ð ð6ð 6ð 6ð 6ð 6ð 6r   