Ë
    áß²j  ã                   óš   — U d Z ddlZddlmZ ddlmZ dZdZ ej                  «       Z	 e«       Z
ded<   d	ed
dfd„Zded
ee   fd„Zdd„Zy)ab  Builder-declared stable prefixes for Anthropic prompt caching.

Skill/webhook/cron builders concatenate a large static scaffold with a small volatile
tail into one user-message string. Only the builder knows where the tail begins, so it
registers the stable prefix here and the cache planner places a breakpoint at that
boundary. Re-parsing marker strings at request time is deliberately avoided: markers
can legitimately appear inside skill bodies, and any delimiter heuristic then shrinks
the cached prefix or absorbs volatile bytes. Process-local by design: any miss falls
back to the whole-message policy.
é    N)ÚOrderedDict)ÚOptionalé    i  @ zOrderedDict[str, None]Ú	_prefixesÚprefixÚreturnc                 ó  — | syt         5  dt        | <   t        j                  | «       t        t        «      t        kD  r-t        j                  d¬«       t        t        «      t        kD  rŒ-t        t        «      dkD  rqt        t        t        t        «      «      t        kD  rMt        j                  d¬«       t        t        «      dkD  r%t        t        t        t        «      «      t        kD  rŒMddd«       y# 1 sw Y   yxY w)zARecord ``prefix`` as the stable scaffold of a just-built message.NF)Úlasté   )	Ú_lockr   Úmove_to_endÚlenÚ_MAX_ENTRIESÚpopitemÚsumÚmapÚ
_MAX_CHARS)r   s    ú@/home/ubuntu/.hermes/hermes-agent/agent/prompt_cache_boundary.pyÚregister_stable_prefixr      s´   € áØÜ	ñ *Ø Œ	�&ÑÜ×Ñ˜fÔ%Ü”)‹nœ|Ò+Ü×Ñ 5ÐÔ)ô ”)‹nœ|Ó+ä”)‹n˜qÒ ¤S¬¬S´)Ó)<Ó%=Ä
Ò%JÜ×Ñ 5ÐÔ)ô ”)‹n˜qÒ ¤S¬¬S´)Ó)<Ó%=Ä
Ó%J÷*÷ *ñ *ús   ŠA!C8Á,BC8Ã8DÚcontentc                 ó  — t         5  d}t        D ]M  }| j                  |«      sŒ| t        |«      d j	                  «       sŒ2|�t        |«      t        |«      kD  sŒL|}ŒO |�t        j                  |«       |cddd«       S # 1 sw Y   yxY w)aa  Longest registered *proper* prefix of ``content`` with a non-whitespace tail.

    The tail must be non-whitespace so the split never yields an empty text
    block (Anthropic rejects it with HTTP 400). A hit refreshes the entry's LRU
    position so a scaffold fired every minute by cron is not evicted by a
    burst of one-off skill invocations.
    N)r   r   Ú
startswithr   Ústripr   )r   Úbestr   s      r   Úfind_stable_prefixr   '   s‡   € ô 
ñ Ø"ˆÜò 	ˆFà×"Ñ" 6Õ*ØœC ›K˜LÐ)×/Ñ/Õ1Ø�\¤S¨£[´3°t³9Ó%<à‘ð	ð ÐÜ×!Ñ! $Ô'Ø÷÷ ò ús   ‡B¥BÁBÁBÂBc                  ób   — t         5  t        j                  «        ddd«       y# 1 sw Y   yxY w)zTest isolation helper.N)r   r   Úclear© ó    r   Úclear_stable_prefixesr    B   s$   € ä	ñ Ü�‰Ô÷÷ ñ ús   ‡%¥.)r   N)Ú__doc__Ú	threadingÚcollectionsr   Útypingr   r   r   ÚLockr   r   Ú__annotations__Ústrr   r   r    r   r   r   ú<module>r(      sm   ðò	ó Ý #Ý ð €ð €
àˆ	�‰Ó€Ù&1£m€	Ð#Ó 3ð
* 3ð 
*¨4ó 
*ð ð ¨°©ó ô6r   