+
    lHàj´�  ã                   ó  a € R: t90 t R t^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
HtHtHtHt ^ RIHtHtHtHt ^ RIHtHtHt ^ RItR;tRR	0tRt] ^ k R
tRt] ^k 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 R llt%]&! 0 R=m4      t'R R lt(R<RRRR/R R lllt)Rt*R t+R<R! R" llt,R<R# R$ llt-R<R% R& llt.R<R' R( llt/R<R) R* llt0R<R+ R, llt1R<R- R. llt2R/t3R0 R1 lt4R>R2 R3 llt5R4 R5 lt6R6 R7 lt7R8 R9 lt8R# )?aq  Write-side safety guards for write_file / patch.

Every guard returns ``None`` when the write may proceed, else an error string
the tool returns verbatim.
Guards, in the order the tools apply them: ``_check_sensitive_path`` (hard
deny), ``_check_binary_document_write``, ``_check_protected_instruction_write``
(ALWAYS ask), ``_check_approval_required_write`` (normal gate),
``_check_cross_profile_path`` (sandbox-mirror lost-work), ``_is_internal_file_tool_content``.
``_stale_overwrite_blocker`` (write_file only, under the per-path lock) refuses a
whole-file overwrite of content this task never saw or that changed since.
N)ÚPath)Úget_nt_namespace_error)Ú
file_state)Úhas_binary_extensionÚhas_opaque_document_extensionÚis_pdf_pathÚis_sqlite_sidecar)Ú_expand_tildeÚ_resolve_path_for_taskÚ_ssh_path_escapes_homeÚ_terminal_env_type_for_task)Ú_has_full_write_baselineÚ_is_own_blind_patchÚ_read_mtime_driftedz/var/run/docker.sockz/run/docker.sockFc                ó$   € V ^8„  d   QhR\         /# ©é   Úreturn©Ústr)Úformats   "ÚB/home/ubuntu/.hermes/hermes-agent/tools/file_tools_write_guards.pyÚ__annotate__r   6   s   € ÷ ,ñ ,œsñ ,ó    c                  óJ   € ^ RI Hp  \        V ! 4       P                  4       4      # )é    ©Úget_config_path)Úhermes_cli.configr   r   Úresolver   s    r   Ú_config_path_resolvedr    6   s   € Ý1Ü‰Ó ×(Ñ(Ó*Ó+Ð+r   c                ó$   € V ^8„  d   QhR\         /# r   r   )r   s   "r   r   r   ;   s   € ÷ 4ñ 4œ3ñ 4r   c                  óh   € ^ RI Hp  \        P                  P	                  \        V ! 4       4      4      # )r   ©Úget_hermes_home)Úhermes_constantsr$   ÚosÚpathÚrealpathr   r#   s    r   Ú_hermes_home_realr)   ;   s"   € Ý0Ü�7‰7×ÑœC¡Ó 1Ó2Ó3Ð3r   c                ó2   € V ^8„  d   QhR\         R,          /# ©r   r   Nr   )r   s   "r   r   r   @   s   € ÷ ñ ¤S¨4¥Zñ r   c            	     ó   € \         '       d   \        #  \        4       #   \         dU     ^ RIHp  \        \        \        T ! 4       4      4      R,          P                  4       4      u #   \         d      R# i ; ii ; i)zîResolved absolute path of the Hermes config file for the ACTIVE profile.

Resolved per call so it tracks the per-turn ``HERMES_HOME`` scope (#107327);
a test may pin it via ``_hermes_config_resolved`` + ``_hermes_config_resolved_loaded``.r#   zconfig.yamlN)	Ú_hermes_config_resolved_loadedÚ_hermes_config_resolvedr    Ú	Exceptionr%   r$   r   r   r   r#   s    r   Ú_get_hermes_config_resolvedr0   @   sm   € ÷
 &Ó%Ü&Ð&ðÜ$Ó&Ð&øÜô ð	Ý8ÜœœS¡Ó!2Ó3Ó4°}ÕD×MÑMÓOÓPÒPøÜô 	Ûð	úðús,   ”	 žA=ª<A)Á&A=Á)A9Á4A=Á8A9Á9A=c                ó2   € V ^8„  d   QhR\         R,          /# r+   r   )r   s   "r   r   r   Y   s   € ÷ ñ œs T�zñ r   c                 óì   € \         '       d   \        #  \        4       #   \         dK     ^ RIHp  \        P                  P                  \        T ! 4       4      4      u #   \         d      R# i ; ii ; i)a~  Realpath of the authoritative Hermes home for the ACTIVE profile.

Resolved per call so it tracks the per-turn ``HERMES_HOME`` scope (#107327);
a test may pin it via ``_real_hermes_home_cached`` + ``_real_hermes_home_loaded``.
Consumers exempting a whole TREE want ``_hermes_exempt_homes()``: under a named
profile this home is ``<root>/profiles/<name>`` and the root is exempt too.r#   N)
Ú_real_hermes_home_loadedÚ_real_hermes_home_cachedr)   r/   r%   r$   r&   r'   r(   r   r#   s    r   Ú_get_real_hermes_homer5   Y   sd   € ÷  ÓÜ'Ð'ðÜ Ó"Ð"øÜô ð	Ý8Ü—7‘7×#Ñ#¤C©Ó(9Ó$:Ó;Ò;øÜô 	Ûð	úðús,   ”	 žA3ª2AÁA3ÁA/Á*A3Á.A/Á/A3c                ó>   € V ^8„  d   QhR\         \        R3,          /# )r   r   .)Útupler   )r   s   "r   r   r   s   s   € ÷ >ñ >œe¤C¨ H�oñ >r   c            	     ó@  € \        4       p V '       g   R#  ^ RIHp V! V 4      pVf   V 3# \        P
                  P                  \        \        \        V4      4      P                  P                  4      4      pV'       d
   W08w  d   W3# V 3#   \         d    Rp Lxi ; i)u  Realpaths of the Hermes home tree(s) the protected-instruction gate must stay out of:
the ACTIVE profile's home, plus the Hermes ROOT when that home is a named profile
(``<root>/profiles/<name>``). Exempting only the profile dir left the root's DIRECT files
(LEDGER.md / MEMORY.md / SOUL.md / AGENTS.md ...) to the ``.hermes`` component rule, which
gated them like a project-local ``<repo>/.hermes/config.yaml`` â€” fail-closed headless
(#110630). They are the agent's own store, governed by their own guards, exactly like
``~/.hermes`` under the default profile. The root is added only when the shape really is a
named profile (``named_profile_home``), so a coincidental ``profiles/`` dir elsewhere never
exempts its parent; the home comes from the ACTIVE scope, never ``HERMES_HOME`` alone.)Únamed_profile_homeN© )
r5   r%   r9   r/   r&   r'   r(   r   r   Úparent)Úhomer9   Úprofile_homeÚroots       r   Ú_hermes_exempt_homesr?   s   s�   € ô !Ó"€DßØˆ	ðÝ7Ù)¨$Ó/ˆð ÒØˆwˆÜ�7‰7×ÑœC¤¤S¨Ó%6Ó 7× >Ñ >× EÑ EÓFÓG€Dß D¤LˆDˆ<Ð=°t°gÐ=øô ô ØŠðús   –B ÂBÂBc                ó<   € V ^8„  d   QhR\         R\         R\         /# ©r   ÚfilepathÚtask_idr   r   )r   s   "r   r   r   ‹   s!   € ÷ ñ œsð ¬Sð ´Sñ r   c                ó^   €  \        \        W4      4      #   \        \        3 d    T u # i ; i)zOTask-resolved path string, falling back to the raw input on resolution failure.)r   r
   ÚOSErrorÚ
ValueError)rB   rC   s   &&r   Ú_resolved_or_rawrG   ‹   s1   € ðÜÔ)¨(Ó<Ó=Ð=øÜ”ZÐ ô ØŠðús   ‚ –,«,c                óJ   € V ^8„  d   QhR\         R\         R\         R,          /# ©r   rB   rC   r   Nr   )r   s   "r   r   r   “   s%   € ÷ ñ ¤Cð ´#ð ÄcÈDÅjñ r   c                ó²  € \        V RR7      pV'       d   V# \        W4      \        P                  P	                  \        V 4      4      3p\        V^ ,          4      '       d   \        V4      R8X  d   RV  R2# \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   R	V  R
2# \        4       pV'       d   WC9   d   RV  R2# R# )zHReturn an error message if the path targets a sensitive system location.ÚWrite)ÚverbÚsshzRefusing to write to z�: it climbs above the SSH home and the remote home could not be detected, so its target cannot be checked. Pass an absolute path.c              3   ól   "  € T F*  qP                  \        4      ;'       g
    V\        9   x € K,  	  R # 5i©N)Ú
startswithÚ_SENSITIVE_PATH_PREFIXESÚ_SENSITIVE_EXACT_PATHS)Ú.0Úcs   & r   Ú	<genexpr>Ú(_check_sensitive_path.<locals>.<genexpr>¢   s,   é € Ð
eÑZdÐUV�<‰<Ô0Ó1×PÐP°QÔ:PÑ5PÔPÓZdùs   ‚4¢4TFz,Refusing to write to sensitive system path: zD
Use the terminal tool with sudo if you need to modify system files.z)Refusing to write to Hermes config file: zz
Agent cannot modify security-sensitive configuration. Edit ~/.hermes/config.yaml directly or use 'hermes config' instead.N)
r   rG   r&   r'   Únormpathr	   r   r   Úanyr0   )rB   rC   Únt_errÚ
candidatesÚhermes_configs   &&   r   Ú_check_sensitive_pathr\   “   sâ   € ô $ H°7Ô;€FßØˆÜ" 8Ó5´r·w±w×7GÑ7GÌÐV^ÓH_Ó7`Ða€JÜ˜j¨�m×,Ò,Ô1LÈWÓ1UÐY^Ô1^à# H :ð .bð bð	c÷ ƒsÑ
eÑZdÓ
e‡s‡s‚sÑ
eÑZdÓ
e×eÒeà:¸8¸*ð ERð Rð	Sô
 0Ó1€Mß˜Ô4à7¸°zð BRð Rð	Sñ r   c                ó\   € V ^8„  d   QhR\         \        \        \        ,          3,          /# r   )r7   ÚboolÚlistr   )r   s   "r   r   r   Á   s    € ÷ 1ñ 1¤u¬T´4¼µ9¨_Õ'=ñ 1r   c                 ó0  €  ^ RI Hp Hp V ! 4       pV! VRRRR7      pV! VRR. R7      p\	        T\
        4      '       g   Rp\	        T\        4      '       g   . pY4 Uu. uF  qU'       g   K  \        T4      NK  	  up3#   \         d    R. 3u # i ; iu upi )uê   Return ``(enabled, extra_patterns)`` from ``security.protected_instruction_files`` /
``security.protected_instruction_extra_patterns`` (fnmatch on basename). Config read
failures keep the gate ON â€” fail-safe for a security boundary.)Úload_configÚcfg_getÚsecurityÚprotected_instruction_filesT©ÚdefaultÚ$protected_instruction_extra_patterns)r   ra   rb   r/   Ú
isinstancer^   r_   r   )ra   rb   ÚcfgÚenabledÚextraÚps         r   Ú_protected_instruction_configrm   Á   s›   € ðß:Ù‹mˆÙ˜#˜zÐ+HÐRVÔWˆÙ˜˜ZÐ)OÐY[Ô\ˆô �gœt×$Ò$ØˆÜ�eœT×"Ò"ØˆØ UÓ0¡U «a”V”S˜–V¡UÑ0Ð0Ð0øô ô Ø�RˆxŠðüò 1s   ‚'A> Á	BÁ+BÁ>BÂBrj   Úextra_patternsc                ó”   € V ^8„  d   QhR\         R\         R\        R,          R\        \         ,          R,          R\         R,          /# )r   rB   rC   rj   Nrn   r   )r   r^   r_   )r   s   "r   r   r   Ó   sD   € ÷ *ñ *¬Cð *¼#ð *Ü.2°T­kð*ä26´sµ)¸dÕ2Bð*äNQÐTXÍjñ*r   c               ó´  a
€ Ve   Vf   \        4       w  r#V'       g   R# \        P                  P                  \	        V 4      4      p \        P                  P                  \        \        W4      4      4      p\        4        F8  pWV8X  g/   VP                  V\        P                  ,           4      '       g   K7   R# 	  WE3 FÕ  p\        P                  P                  V4      pVP                  4       o
S
\         9   gA   \"        ;QJ d    V
3R lV 4       F  '       g   K   RM	  RM! V
3R lV 4       4      '       d   Vu # VP%                  RR4      P'                  R4      P)                  R4      p	\+        V	4      ^8¼  g   KÃ  V	R,          R8X  g   KÓ  Vu # 	  R#   \        \        \        3 d$    \        P                  P                  T4      p EL\i ; i)	a¿  Return a short label when ``filepath`` targets a protected instruction file, else ``None``.
Matches BOTH the normalized input and its realpath so no symlink direction escapes.

Matching runs on BOTH the normalized input path and its realpath so neither a symlink pointing AT a
protected file (#41351) nor a protected name that is itself a symlink escapes the gate. ``..`` traversal
is neutralized by normpath/realpath before the basename compare.
Nc              3   ón   <"  € T F*  p\         P                   ! SVP                  4       4      x € K,  	  R # 5irO   )ÚfnmatchÚlower)rS   ÚpatternÚ
base_lowers   & €r   rU   Ú0_protected_instruction_reason.<locals>.<genexpr>ô   s*   øé € ð A\ÙLZÀ”—’ 
¨G¯M©M«O×<Ð<ËNùs   ƒ25TFÚ\Ú/z.hermeséþÿÿÿ)rm   r&   r'   rW   r	   r(   r   r
   rE   rF   ÚRuntimeErrorr?   rP   ÚsepÚbasenamers   Ú _PROTECTED_INSTRUCTION_BASENAMESrX   ÚreplaceÚrstripÚsplitÚlen)rB   rC   rj   rn   Ú
normalizedÚresolvedÚ	real_homeÚ	candidateÚbaseÚpartsru   s   &&$$      @r   Ú_protected_instruction_reasonrˆ   Ó   sy  ø€ ð ‚˜.Ò0Ü"?Ó"AÑˆßÙä—‘×!Ñ!¤-°Ó"9Ó:€Jð0Ü—7‘7×#Ñ#¤CÔ(>¸xÓ(QÓ$RÓSˆô *Ö+ˆ	ØÔ  H×$7Ñ$7¸	ÄBÇFÁFÕ8J×$KÔ$KÚñ ,ð !Ó+ˆ	Ü�w‰w×Ñ 	Ó*ˆØ—Z‘Z“\ˆ
ØÔ9Ô9¿S»Sô A\ÙLZóA\¿S¿SºSô A\ÙLZóA\÷ >\ò >\àŠKð ×!Ñ! $¨Ó,×3Ñ3°CÓ8×>Ñ>¸sÓCˆÜˆu‹:˜Ž?˜u R�y¨IÖ5ØÒñ ,ñ øô1 ”Z¤Ð.ô 0Ü—7‘7×#Ñ# JÓ/‹ð0ús   Á	1F Æ5GÇGz<requires approval but the approval subsystem is unavailable.zNrequires approval but no interactive user or gateway is present to approve it.c                ó`   € V ^8„  d   QhR\         \        ,          R\        R\        R,          /# )r   ÚreasonsrC   r   N©r_   r   )r   s   "r   r   r     s1   € ÷ S*ñ S*´T¼#µYð S*Ìð S*Ô]`ÐcgÕ]gñ S*r   c                ó  € RP                  \        P                  V 4      4      pRV R2pRV R2pRV R2pVP                  RR	7      pVP                  R
R	7      p ^ RIHp ^ RIHp	Hp
 ^ RI	H
p ^ RIHp T
! 4       p TP                  ;_uu_ 4        TP                   P#                  T4      pRRR4       Xe    RTRRRR.RTRRRR/pT! YÞTRR7      pTP#                  R4      '       d   TP                  RR	7      # TP#                  R4      '       d   TP                  RTR,           R2R	7      # TP#                  R4      TP#                  R4      '       * ppM¯ ^ R IHp T! 4       pTf   TP                  \(        R	7      # ^ R!IHp T! 4       '       d   TP                  \(        R	7      # \        YCRR.TR"R#7      pT	! R)/ TB  T! YCRRTR$7      pT	! R*/ TBRT/B  TR8X  d"   TP                  R%\-        TR&R'4       R2R	7      # TR(8H  pT'       g
   TR+9   d   R# T'       d   T# T#   \         d    TP                  \        R	7      u # i ; i  + '       g   i     EL§; i  \         d    Rp ELºi ; i  \         d    Rp ELi ; i),a  Ask the human to approve a write to protected instruction file(s); ``None`` when approved.

Deliberately NOT routed through ``_run_approval_gate`` (honors --yolo and
allowlists): this gate is one-operation approval EVERY time, no persisted
scope, fail-closed without a human channel.
ú, z.Write to protected agent-instruction file(s): zf. These files steer future agent behavior; approval is always required (not bypassed by auto-approve).ú
<write to Ú>z7BLOCKED: write to protected agent-instruction file(s) (z‹) {why} The user has NOT consented to this write. Do NOT retry it or attempt the same edit via another path (terminal, execute_code, etc.).zJapproval prompt timed out without a user response. Silence is not consent.©Úwhyzwas denied by the user.N)Ú_fire_approval_hookÚget_current_session_key)Ú_await_gateway_decision)Úprompt_dangerous_approvalÚcommandÚpattern_keyÚprotected_instruction_fileÚpattern_keysÚdescriptionÚallow_permanentFÚallow_sessionÚgateway)ÚsurfaceÚnotify_failedzBrequires approval but the approval request could not be delivered.Ú	cancelledz1approval was withdrawn before the user answered (z).Úchoicerƒ   )Ú_get_approval_callback)Ú_no_user_can_answerÚcli)r–   rš   r—   r™   Úsession_keyrž   )r›   rœ   Úapproval_callbackz<approval prompt could not be delivered or was not answered (Úcausez	no answerÚtimeout)Úpre_approval_request)Úpost_approval_response>   ÚonceÚalwaysÚsession)ÚjoinÚdictÚfromkeysr   Útools.approvalÚapprovalÚtools.approval_contextr’   r“   Útools.approval_gateway_waitr”   Útools.approval_promptr•   r/   Ú_APPROVAL_UNAVAILABLEÚ_lockÚ_gateway_notify_cbsÚgetÚtools.terminal_toolr¢   Ú	_NO_HUMANr£   Úgetattr)rŠ   rC   Útargetsrš   ÚdisplayÚblockedÚ	timed_outÚdeniedÚ	_approvalr’   r“   r”   r•   r¥   Ú	notify_cbÚapproval_dataÚdecisionr¡   Útimedr¢   Úcallbackr£   Úhook_kwargss   &&                     r   Ú'_request_protected_instruction_approvalrÉ     sÅ  € ð �i‰iœŸ™ gÓ.Ó/€Gà
8¸¸	ð B3ð 	3ð ð ˜7˜) 1Ð%€Gà
AÀ'Àð Kð 	ð ð
 —‘Ð#o�Óp€IØ�^‰^Ð 9ˆ^Ó:€Fð9Ý*ßWÝGÝCñ *Ó+€KðØ�_�_‹_Ø!×5Ñ5×9Ñ9¸+ÓFˆI÷ ð
 Òà�wØÐ7ØÐ9Ð:Ø˜;Ø˜uØ˜Uð$ˆñ +¨;À=ÐZcÔdˆØ�<‰<˜×(Ò(Ø—>‘>Ð&j�>ÓkÐkØ�<‰<˜×$Ò$Ø—>‘>Ð(YÐZbÐcnÕZoÐYpÐprÐ&s�>ÓtÐtØ Ÿ™ XÓ.°H·L±LÀÓ4LÔ0L�ˆ�ð	ÝBÙ-Ó/ˆHð Òð —>‘>¤i�>Ó0Ð0õ 	?Ù× Ò Ø—>‘>¤i�>Ó0Ð0ô  7ÐQmØ)EÐ(FÐT_ÐinôpˆáÑB°kÒBÙ*Ø°%ÀuÐ`hôjˆáÑS¸ÑSÈFÓSØ�[Ô Ø—>‘>ð '*Ü*1°&¸'À;Ó*OÐ)PÐPRð'T�>ó Uð Uà˜)Ñ#ˆç�VÐ<Ô<Ùßˆ9Ð) 6Ð)øôs ô 9Ø�~‰~Ô"7ˆ~Ó8Ò8ð9ú÷ �_ˆ_ûäô Ø‹	ðûô, ô 	Ø‹Hð	úsT   ÁH% Á>I  ÂIÂ.I  ÅI4 È%!I	ÉI	ÉI	ÉI  ÉI  É I1É0I1É4JÊJc                ó`   € V ^8„  d   QhR\         \        ,          R\        R\        R,          /# ©r   ÚpathsrC   r   Nr‹   )r   s   "r   r   r   Z  s1   € ÷ 
Eñ 
E¬d´3­ið 
EÄ#ð 
EÔVYÐ\`ÕV`ñ 
Er   c                óº   aaa€ \        4       w  ooS'       g   R# VVV3R lV  4        Uu. uF  pV'       g   K  VNK  	  ppV'       g   R# \        VS4      # u upi )z‹Gate a write/patch touching protected instruction files. ONE protected file gates
the ENTIRE multi-file patch (one prompt, all-or-nothing).Nc              3   óB   <"  € T F  p\        VSSSR 7      x € K  	  R# 5i))rj   rn   N)rˆ   )rS   rl   rj   rk   rC   s   & €€€r   rU   Ú5_check_protected_instruction_write.<locals>.<genexpr>`  s'   øé € ð +Ù$)˜qô 9¸¸GÈWÐej×kÑkÛ$)ùs   ƒ)rm   rÉ   )rÌ   rC   ÚrrŠ   rj   rk   s   &f  @@r   Ú"_check_protected_instruction_writerÑ   Z  s_   ú€ ô 3Ó4�N€GˆUßÙö+Ù$)ô+ó 1ñ +�QÜ./÷ ˆqñ +€Gð 1çÙÜ2°7¸GÓDÐDùò	1s
   «
AºAc                ó`   € V ^8„  d   QhR\         \        ,          R\        R\        R,          /# rË   r‹   )r   s   "r   r   r   g  s1   € ÷ -Fñ -F¬$¬s­)ð -F¼cð -FÔRUÐX\ÕR\ñ -Fr   c                óŠ  €  ^ RI Hp T  Uu. uF  q2! \        Y14      4      '       g   K  TNK  	  ppT'       g   R# RP	                  \
        P                  T4      4      pRT R2pRT R2p ^ RIHp TP                  R	TR
T R2TP                  RR7      TP                  RR7      R	RTP                  \        R7      R7      p	T	P                  R4      '       d   R# T	P                  R4      ;'       g    TP                  RR7      #   \         d     R# i ; iu upi   \         d    TP                  \        R7      u # i ; i)zÙGate a write/patch touching an approval-required path (``~/.ssh/config`` can steer
execution via ``ProxyCommand``). Routine gate: once/session/always, honors --yolo,
fail-closed without an interactive/gateway channel.)Úis_write_approval_requiredNr�   z$Write to SSH client config file(s): zs. The SSH config can carry ProxyCommand / Match exec directives that run commands, so writes require your approval.z&BLOCKED: write to SSH config file(s) (zf) {why} Do NOT retry it via another path (terminal, execute_code) without the user's explicit consent.r�   Ússh_config_writerŽ   r�   z2requires approval but this cron session denies it.zÂrequires approval but single-query (-q) sessions run without a user present to approve it. To allow flagged actions in single-query mode, set approvals.single_query_mode: approve in config.yaml.T)r—   rš   Údisplay_targetÚcron_deny_messageÚsingle_query_deny_messageÚautoapprove_log_prefixÚfail_closed_when_no_humanÚno_human_block_messageÚapprovedÚmessagezwas denied.)Úagent.file_safetyrÔ   r/   rG   r®   r¯   r°   r±   r²   r   r¶   Ú_run_approval_gater»   r¹   )
rÌ   rC   rÔ   rl   r½   Údisplay_targetsrš   r¿   rÂ   Úresults
   &&        r   Ú_check_approval_required_writerâ   g  s_  € ðÝ@ñ  Ó\™%�QÐ#=Ô>NÈqÓ>Z×#[�qˆq™%€GÐ\ßÙà—i‘i¤§¡¨gÓ 6Ó7€Oà
.¨Ð.?ð @9ð 	9ð ð
 1°Ð0Að B/ð 	/ð ð
9Ý*ð ×)Ñ)Ø&ØØ# OÐ#4°AÐ6Ø!Ÿ.™.Ð-a˜.ÓbØ")§.¡.ð*ð #1ó #+ð
  2Ø"&Ø&Ÿ~™~´)˜~Ó<ð *ó >€Fð ‡z�z�*×ÒÙØ�:‰:�iÓ ×EÐE G§N¡N°} NÓ$EÐEøôO ô Úðüò
 ]øô  ô 9Ø�~‰~Ô"7ˆ~Ó8Ò8ð9ús-   ‚D ŒD©DÁ,D ÄDÄDÄ!EÅEc                ó>   € V ^8„  d   QhR\         R\         R,          /# )r   rC   r   Nr   )r   s   "r   r   r   —  s   € ÷ ñ ´3ð ÄsÈTÅzñ r   c                óð  €  ^ RI HpHpHpHp V! V 4      pT;_uu_ 4        VP                  V4      ;'       g    VP                  V 4      pRRR4       XeD   VP                  P                  R8H  ;'       d    \        \        VRR4      4      pV'       d   R# R# V! 4       pTP                  R4      R8X  d   TP                  R	R
4      '       d   R# R#   + '       g   i     L�; i  \         d     R# i ; i)zPReturn the container-side Hermes mirror prefix for persistent Docker file tools.)Ú_active_environmentsÚ	_env_lockÚ_get_env_configÚ_resolve_container_task_idNÚDockerEnvironmentÚ_persistentFz/root/.hermesÚenv_typeÚdockerÚcontainer_persistentT)rº   rå   ræ   rç   rè   r¹   Ú	__class__Ú__name__r^   r¼   r/   )	rC   rå   ræ   rç   rè   Úcontainer_keyÚenvÚpersistent_dockerÚconfigs	   &        r   Ú%_get_container_mirror_prefix_for_taskrô   —  sá   € ð÷	Zó 	Zá2°7Ó;ˆßŠYØ&×*Ñ*¨=Ó9×^Ð^Ð=Q×=UÑ=UÐV]Ó=^ˆC÷ àŠ?Ø!$§¡×!7Ñ!7Ð;NÑ!N÷ "Nð "NÜ%)¬'°#°}ÀeÓ*LÓ%Mð ç&7�?ÐA¸TÐAÙ Ó"ˆð ‡z�z�*Ó Ô)¨f¯j©jÐ9OÐQU×.VÒ.VÙÙ÷ �Yûô ô Úðús@   ‚C&  +CÁ+C& Á7C& ÂC& ÂC& ÂC& ÃC#	ÃC& Ã&C5Ã4C5c                óJ   € V ^8„  d   QhR\         R\         R\         R,          /# rI   r   )r   s   "r   r   r   «  s+   € ÷ pñ p¬ð p´cð pÌ#ÐPTÍ*ñ pr   c                ó�   €  ^ RI HpHp \	        Y4      pT! T4      pTe   T# T! T\        T4      R7      #   \         d     R# i ; i)u  Soft-guard: warn when ``filepath`` lands on a host-side or Docker sandbox MIRROR of
Hermes state (a write the host never reads). Not profile isolation â€” that guard was
removed; ``cross_profile=True`` keeps bypassing this one for replay compat. Fails open.)Úget_container_mirror_warningÚget_sandbox_mirror_warningN)Úmirror_prefix)rÞ   r÷   rø   r/   rG   rô   )rB   rC   r÷   rø   rƒ   Úwarnings   &&    r   Ú_check_cross_profile_pathrû   «  sS   € ðß^ô   Ó2€HÙ(¨Ó2€GØÒØˆÙ'¨Ô@eÐfmÓ@nÔoÐoøô ô Úðús   ‚6 ¶AÁAc                ó<   € V ^8„  d   QhR\         R\         R\         /# rA   r   )r   s   "r   r   r   º  s!   € ÷ &ñ &¬ð &´sð &Ì3ñ &r   c                óè  € ^ RI HpHp  \        \	        W4      4      p V! V4      pT! T4      '       d6   Tf   \        T 4      MTp \        T4      P                  4       '       d   R# R#  TP                  TP                  T;'       g    T 4      4      w  rxTR9   d   R# TR9   d   R# R#   \
         d    Rp Lœi ; i  \
         d     R# i ; i  \         d     R# i ; i  \
         d     R# i ; i)u<  Is a REGULAR file at *filepath* present where the write will execute
(the task's backend, not the controller's disk â€” #122662)?

Returns ``"exists"``, ``"absent"`` or ``"unavailable"``. Host-backed envs
keep ``Path.is_file`` semantics; anything not proven absent is
``"unavailable"`` and callers must fail closed.
)Ú_file_ops_uses_host_pathsÚ_get_file_opsNÚunavailableÚexistsÚabsent)ÚokÚbad_size)ÚmissingÚnot_regular)Útools.file_toolsrþ   rÿ   r   r
   r/   r	   r   Úis_filerE   Ú_probe_regular_fileÚ_expand_path)	rB   rC   rþ   rÿ   rƒ   Úfile_opsÚprobeÚ_sizeÚstatuss	   &&       r   Ú_target_regular_file_stater  º  s	  € ÷ JðÜÔ-¨hÓ@ÓAˆðÙ  Ó)ˆñ ! ×*Ò*ð ,4Ò+;”˜hÔ'Àˆð	Ü# E›{×2Ñ2×4Ò4�8ÐB¸(ÐBðð !×4Ñ4°X×5JÑ5JÈ8×K_ÐK_ÐW_Ó5`Óa‰ˆð Ð#Ô#áØÐ+Ô+ñ Ùøô7 ô ØŠðûô ô Úðûô ô 	Úð	ûô ô ÚðúsR   ŠB+ ŸB> Á C Á(C Á+C" Â
C" Â+B;Â:B;Â>CÃCÃCÃCÃ"C1Ã0C1c                óJ   € V ^8„  d   QhR\         R\         R\         R,          /# rI   r   )r   s   "r   r   r   ã  s+   € ÷ @ñ @¬3ð @¼ð @ÌSÐSWÍZñ @r   c                óŠ  € \         P                  P                  V 4      ^,          P                  4       p\	        V 4      '       d
   RV  RV R2# \        V 4      '       d
   RV  RV R2# \        V 4      pV'       g   \        V 4      '       d7   \        W4      pVR8X  d   V'       d   RV  R2# R	V  RV R
2# VR8X  d   RV  R2# R# )u‚  Reject text-tool writes that would corrupt a binary document (read_file showed
EXTRACTED text, so the model may write it back). Opaque document formats and
SQLite sidecars (-wal/-shm/-journal) are always rejected; .pdf and every other
BINARY_EXTENSIONS suffix only when OVERWRITING an existing file (raw PDF syntax
is text-authorable and text fixtures named ``*.db`` exist). "Existing" is asked
of the filesystem the write will hit â€” the task's backend, via
``_target_regular_file_state`` â€” never the controller's disk alone (#122662).

``read_file`` auto-extracts .docx/.xlsx/.pptx (and PDF, via anydoc) to readable text, so the model
plausibly believes it holds the file's contents and tries to write the edited text back with
write_file/patch. A plain-text write can never produce a valid OOXML/OLE/ODF container, so that write
silently destroys the document (port of nearai/ironclaw#7109).
z1Refusing to write plain text to binary document 'z' (a  ). A text write cannot produce a valid document container and would corrupt the file (read_file showed you EXTRACTED text, not the real bytes). Use the docx/xlsx/powerpoint skills or a library like python-docx/openpyxl/python-pptx via the terminal to create or edit this document.z7Refusing to write plain text to binary SQLite sidecar 'zÔ). A -wal/-shm/-journal file holds raw database pages that SQLite reads on the next open; text there corrupts the database. Use the sqlite3 CLI or a SQLite library via the terminal to modify the database instead.r  z$Refusing to overwrite existing PDF 'uå   ' with plain text. read_file showed you EXTRACTED text, not the real bytes â€” writing text back would destroy the document. Use the pdf skill or a PDF library via the terminal to modify it. (Creating a NEW .pdf file is allowed.)z,Refusing to overwrite existing binary file 'u1  ) with plain text â€” read_file showed you extracted or mojibake text, not the real bytes, and writing text back would destroy the file. Use a binary-aware tool via the terminal to modify it (for SQLite databases, the sqlite3 CLI or a SQLite library). (Creating a NEW file with this extension is allowed.)r   zRefusing to write to 'uì   ': could not establish whether the target file already exists where this write would execute (the terminal environment may be starting, unreachable, or was removed). The file was NOT modified â€” retry once the environment is reachable.N)	r&   r'   Úsplitextrs   r   r   r   r   r  )rB   rC   ÚextÚpdfÚstates   &&   r   Ú_check_binary_document_writer  ã  s	  € ô �'‰'×
Ñ
˜8Ó
$ QÕ
'×
-Ñ
-Ó
/€CÜ$ X×.Ò.à?À¸zÈÈSÈEð Rð ð	ô ˜×"Ò"àEÀhÀZÈsÐSVÐRWð X ð  ð	!ô �hÓ
€Cß
Ô" 8×,Ò,Ü*¨8Ó=ˆØ�HÔßà:¸8¸*ð E#ð #ð$ð ?¸x¸jÈÈCÈ5ð QHð HðIð �MÔ!ð )¨¨
ð 3 ð  ð!ñ r   uœ   File unchanged since last read. The content from the earlier read_file result in this conversation is still current â€” refer to that instead of re-reading.c          	      ód   € V ^8„  d   QhR\         R\         R,          R\         R\         R,          /# )r   rB   rƒ   NrC   r   r   )r   s   "r   r   r   -  s3   € ÷ %ñ %¤sð %´c¸Dµjð %Ì3ð %ÔSVÐY]ÕS]ñ %r   c                ó�  € \         P                  ! 4       '       d   R# V'       d   \         P                  ! W!4      MRpV'       d   V# \        W4      '       d   V  R2# V'       d   \	        W4      '       d   R#  \        V4      P                  4       pT'       g   R# \        Y4      '       d    R# T R2#   \         d     R# i ; i)a&  Reason write_file must NOT replace the existing file, else ``None``.

Refuses BEFORE any disk mutation (the pre-#65604 warning arrived after the
clobber): a sibling/external/partial-read staleness finding, or an existing
file with no full-content baseline for this task (never read in full, read
redacted, only patched without one). Net-new files, files this task fully read
(in one page or by paging contiguously to the last line), wrote, or patched
from such a baseline, unresolvable paths and the file-state kill switch all
let the write proceed.
Nzj was modified since you last read it (external edit or concurrent agent). Re-read the file before writing.z¨Your patch changed this file without a full view of its current content. Read the current file in full before a whole-file overwrite, or continue with targeted patches.u7   exists but this task has not seen its full current content (never read, patched without a prior full read, or only a redacted/partial view). Read the file â€” every page of it, if it needs offset/limit â€” or use patch for a targeted edit; a stale conversation copy must not overwrite the current disk content.)	r   Úguard_disabledÚcheck_staler   r   r   r  rE   r   )rB   rƒ   rC   Ústaler  s   &&&  r   Ú_stale_overwrite_blockerr  -  sÇ   € ô × Ò ×"Ò"Ùß9AŒJ×"Ò" 7Ô5Àt€EßØˆÜ˜8×-Ò-àˆjð Bð Bð	C÷ Ô/°×BÒBÙðÜ�h“×&Ñ&Ó(ˆ÷ ÙÜ˜8×-Ò-ðXñ	Yð ˆ*ð ð 	ðøô ô Úðús   Á:B6 Â6CÃCc                óV   € V ^8„  d   QhR\         R\         R\         R,          R\        /# )r   rB   Úreasonrƒ   Nr   )r   r¯   )r   s   "r   r   r   U  s-   € ÷ ñ ¤3ð ´ð ¼sÀT½zð ÔUYñ r   c                ó<   € RRV  RV R2RRRV /pV'       d   W#R&   V# )	zpModel-facing refusal payload for write_file; ``stale_write_blocked`` lets
callers tell it apart from I/O errors.ÚerrorzRefusing to overwrite z: zû The file was NOT modified. Reload the current contents with read_file (every page, for a file that needs offset/limit), merge the requested change, then call write_file again. For small edits, prefer patch so existing unrelated changes are preserved.Ústale_write_blockedTr'   Úresolved_pathr:   )rB   r  rƒ   rá   s   &&& r   Ú_stale_write_refusalr#  U  sC   € ð 	Ø$ X J¨b°°ð 98ð 8ð
 	˜tØ�ð	€F÷ Ø"*ˆÑØ€Mr   c                ó0   € V ^8„  d   QhR\         R\        /# ©r   Úcontentr   ©r   r^   )r   s   "r   r   r   g  s   € ÷ >ñ >¬3ð >´4ñ >r   c                óÞ   € \        V \        4      '       g   R# V P                  4       p\        V4      ;'       d4    \        V9   ;'       d#    \        V4      ^\        \        4      ,          8*  # )u²   True when content is the read_file dedup status message, verbatim or lightly framed
(contains the full message and is <=2x its length â€” a real file quoting it would be longer).F)rh   r   Ústripr^   Ú_READ_DEDUP_STATUS_MESSAGEr�   )r&  Ústrippeds   & r   Ú_is_internal_file_status_textr,  g  s^   € ô �gœs×#Ò#ÙØ�}‰}‹€HÜ�‹>÷ >ð >Ô8¸HÑD÷ >ð >ÜˆH‹˜œSÔ!;Ó<Õ<Ñ<ð>r   c                ó0   € V ^8„  d   QhR\         R\        /# r%  r'  )r   s   "r   r   r   q  s   € ÷ 2ñ 2¼ð 2Äñ 2r   c                óx  € \        V \        4      '       g   R# V P                  4        Uu. uF  qP                  4       '       g   K  VNK  	  pp\	        V4      ^8  d   R# . pV Fa  pVP                  4       P                  R4      w  rEpV'       g   K/  VP                  4       '       g   KG  VP                  \        V4      4       Kc  	  \	        V4      ^8  g!   \	        V4      \	        V4      ,          R8  d   R# \        R \        P                  ! V4       4       4      pV\	        V4      ^,
          8¬  # u upi )z True for content dominated by read_file's ``LINE_NUM|CONTENT`` display (>=60% of
non-empty lines are consecutive numbered lines; a lone ``1|value`` is allowed).FÚ|g333333ã?c              3   óH   "  € T F  w  rW!^,           8X  g   K  ^x € K  	  R# 5i)é   Nr:   )rS   ÚprevÚcurrents   &  r   rU   Ú>_looks_like_read_file_line_numbered_content.<locals>.<genexpr>€  s"   é € ÐgÑ3O¡- $ÐSZÐefÕ^fÑSfŸAšAÓ3Oùs   ‚"˜
")rh   r   Ú
splitlinesr)  r�   ÚlstripÚ	partitionÚisdigitÚappendÚintÚsumÚ	itertoolsÚpairwise)r&  ÚlineÚlinesÚnumberedÚprefixr{   Ú_restÚconsecutive_pairss   &       r   Ú+_looks_like_read_file_line_numbered_contentrD  q  sï   € ô �gœs×#Ò#ÙØ%×0Ñ0Ô2ÓCÑ2�d·j±j·l�TˆTÑ2€EÐCÜ
ˆ5ƒz�A„~ÙØ€HÛˆØ!Ÿ[™[›]×4Ñ4°SÓ9Ñˆ�Uß‰3�6—>‘>×#Ô#Ø�O‰OœC ›KÖ(ñ ô ˆ8ƒ}�qÔœC ›M¬C°«JÕ6¸Ô<ÙÜÑg´9×3EÒ3EÀhÔ3OÓgÓgÐØ¤ H£°Õ 1Ñ1Ð1ùò Ds   «D7ÁD7c                ó0   € V ^8„  d   QhR\         R\        /# r%  r'  )r   s   "r   r   r   „  s   € ÷ jñ j¬Cð j´Dñ jr   c                ó>   € \        V 4      ;'       g    \        V 4      # )zLReturn True when content is file-tool display text, not intended file bytes.)r,  rD  )r&  s   &r   Ú_is_internal_file_tool_contentrG  „  s   € ä(¨Ó1×iÐiÔ5`ÐahÓ5iÐir   c                ó„   € V ^8„  d   Qh/ ^ \         9   d   \        R,          ;R&   ^\         9   d   \        R,          ;R&   # )r   Nr.   r4   )Ú__conditional_annotations__r   )r   s   "r   r   r      s<   € ÷ 
ñ 
÷^ +Ò *œ˜t�Ñ *ñ_
÷b ,Ò +œ# �*Ñ +òc
r   )z/etc/z/boot/z/usr/lib/systemd/z/private/etc/z/private/var/db/z/private/var/root/re   >   úsoul.mdú	agents.mdú	claude.mdú.cursorrulesrO   ):rI  Ú__doc__rr   r&   Úpathlibr   rÞ   r   Útoolsr   Útools.binary_extensionsr   r   r   r   Útools.file_tools_pathsr	   r
   r   r   Útools.file_tools_read_trackingr   r   r   r<  rQ   rR   r.   r-   r4   r3   r    r)   r0   r5   r?   rG   r\   Ú	frozensetr}   rm   rˆ   r¶   r»   rÉ   rÑ   râ   rô   rû   r  r  r*  r  r#  r,  rD  rG  r   )rI  s   @r   Ú<module>rU     s&  øðö
ó Û 	Ý å 4Ý ÷ó ÷`ó `ç mÑ mÛ ð
.Ð ð 1Ð2DÐEÐ ð '+Ð Ó *Ø!&Ð Ø'+Ð Ó +Ø Ð õ,õ
4õ
õ2õ4>õ0÷ñT $-ò .9ó $:Ð  õ1ñ$*Ø<@ð*àEI÷*ð *ðZ WÐ Ø\€	÷S*÷l
E÷-F÷`÷(p÷&÷R@ðJ=ð õ%÷Põ$>õ2÷&jr   