+
    lHàj°:  ã                   ó  a€ R2 t0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
 ^ RIHtHt ]P                  ! R4      t]R R l4       t^R^R	^R
^R^R^	R^R^R^R^R^R/t] ^ k R R lt/ R3 U u/ uF  q ^R/bK	  	  up CR4 U u/ uF  q ^R/bK	  	  up CR5 U u/ uF  q ^R/bK	  	  up CR^R/R^R^R^R^R/R^R //C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/ ltR0 R1 ltR# u up i u up i u up i )6a7  Foreground result post-processing for the terminal tool (cwd dual-write,
sudo handling, transform hook, truncation, ANSI strip, redaction, exit-code
notes/hints, spill redaction, verification evidence) + exit-code tables. Lazy
``tools.terminal_tool`` lookups keep the origin's monkeypatch points authoritative.
N)Úcontextmanager)ÚPath)ÚAnyÚOptionalztools.terminal_toolc                ó$   € V ^8„  d   QhR\         /# )é   Úlabel©Ústr)Úformats   "Ú?/home/ubuntu/.hermes/hermes-agent/tools/terminal_tool_result.pyÚ__annotate__r      s   € ÷ 8ñ 8”#ñ 8ó    c              #  ól   "  €  Rx € R#   \          d    \        P                  RT RR7        R# i ; i5i)z>Best-effort block: swallow any exception, logging it at DEBUG.Nz	%s failedT©Úexc_info)Ú	ExceptionÚloggerÚdebug)r   s   &r   Ú_quietr      s-   é € ð8ÝøÜô 8Ü�‰�[ %°$ˆ×7ð8üs   ‚4„
 ˆ4Š#1­4°1±4zSIGQUIT (quit from keyboard)uE   SIGILL (illegal instruction â€” corrupt binary or wrong architecture)uJ   SIGABRT (abort â€” assertion failure, fatal runtime error, or glibc abort)u;   SIGBUS (bus error â€” misaligned or unmapped memory access)z>SIGFPE (fatal arithmetic error, e.g. integer division by zero)uT   SIGKILL â€” often the kernel OOM killer on memory exhaustion, or an explicit kill -9u4   SIGSEGV (segmentation fault â€” the program crashed)uN   SIGPIPE (wrote to a closed pipe â€” e.g. output piped to a reader that exited)uF   SIGTERM (terminated â€” kill/timeout or shutdown requested it to stop)z!SIGXCPU (CPU time limit exceeded)z"SIGXFSZ (file size limit exceeded)c                ó>   € V ^8„  d   QhR\         R\        R,          /# )r   Ú	exit_codeÚreturnN)Úintr
   )r   s   "r   r   r   /   s   € ÷ ñ ¤cð ¬c°D­jñ r   c                óp  € V ^ 8  d\   V ) pV^8X  d   R# \         P                  V4      ;p'       d	   RV RV 2#  \        P                  ! V4      P                  pRV RV R2# V ^€8”  d7   \         P                  V ^€,
          4      ;p'       d   RV  R	V ^€,
           RV 2# R#   \
         d	    RT 2p LZi ; i)
zÒNote for a signal-termination exit code, or None. Negative codes are
definite (subprocess semantics); 128+signum is the shell convention and a
program *can* exit 139 itself, so those notes hedge with "usually".NzCommand terminated by signal z: zsignal zCommand terminated by z	 (signal Ú)z
Exit code z4 usually means the command was terminated by signal )Ú_SIGNAL_EXIT_NOTESÚgetÚsignalÚSignalsÚnameÚ
ValueError)r   ÚsignumÚnoter    s   &   r   Ú_interpret_signal_exitr$   /   sÞ   € ð �1„}Ø�ˆØ�QŒ;ÙÜ%×)Ñ)¨&Ó1Ð1ˆ4Ö1Ø2°6°(¸"¸T¸FÐCÐCð	&Ü—>’> &Ó)×.Ñ.ˆDð (¨ v¨Y°v°h¸aÐ@Ð@Ø�3„Ô$6×$:Ñ$:¸9Às½?Ó$KÐK˜DÖKØ˜Y˜Kð ((Ø(1°C­Ð'8¸¸4¸&ðBð 	Cáøô ô 	&Ø˜V˜HÐ%ŠDð	&ús   º B" Â"B5Â4B5zNo matches found (not an error)z%Files differ (expected, not an error)z5Condition evaluated to false (expected, not an error)ÚfindzGSome directories were inaccessible (partial results may still be valid)ÚcurlzCould not resolve hostzFailed to connect to hostz2HTTP response code indicated error (e.g. 404, 500)zOperation timed outÚgituL   Non-zero exit (often normal â€” e.g. 'git diff' returns 1 when files differ)u;  The execution environment was recreated while running this command (the previous container/sandbox was gone). Persistent files were restored where the backend supports it, but background processes and any files outside persisted paths from earlier commands may be lost â€” verify state before relying on prior work.c                óJ   € V ^8„  d   QhR\         R\        R\         R,          /# )r   Úcommandr   r   N)r
   r   )r   s   "r   r   r   \   s*   € ÷ Añ A¤#ð A´#ð A¼#À½*ñ Ar   c                ó2  € V^ 8X  d   R# \        V4      ;pe   V# \        P                  ! RV 4      pV'       d
   VR,          MT P                  4       p\	        R VP                  4        4       R4      p\
        P                  V/ 4      P                  V4      # )zÔNote for a non-zero exit code that is informational rather than an
error (grep=1 "no matches", diff=1 "files differ", signal deaths), so the
model doesn't burn turns investigating it. None when 0 or a real error.Nz\s*(?:\|\||&&|[|;])\s*c              3   ó’   "  € T F=  pR V9  g   VP                  R4      '       g   K#  VP                  R4      R,          x € K?  	  R# 5i)Ú=Ú-Ú/Néÿÿÿÿ)Ú
startswithÚsplit)Ú.0Úws   & r   Ú	<genexpr>Ú'_interpret_exit_code.<locals>.<genexpr>o   s;   é € ð ;Ñ/C¨!Ø 1œ¨¯©°S×(9ô &�Q—W‘W˜S“\ "×%Ò%Ó/Cùs
   ‚ A§ AÚ r/   )r$   Úrer1   ÚstripÚnextÚ_EXIT_CODE_SEMANTICSr   )r)   r   Úsignal_noteÚsegmentsÚlast_segmentÚbase_cmds   &&    r   Ú_interpret_exit_coder?   \   s�   € ð �A„~ÙÜ-¨iÓ8Ð8ˆÒEð Ðô �xŠxÐ1°7Ó;€Hß$,�H˜R–L°'×@Ñ@ÓB€LÜñ ;¨|×/AÑ/AÔ/Có ;Ø<>ó@€Hä×#Ñ# H¨bÓ1×5Ñ5°iÓ@Ð@r   c                ót   € V ^8„  d   QhR\         R\         R\         R\        \         \        \        3,          /# )r   r)   ÚoutputÚenv_typer   )r
   ÚtupleÚbool)r   s   "r   r   r   t   s4   € ÷ .ñ .œsð .¬Cð .¼3ð .Ä5ÌÌdÔTXÈÕCYñ .r   c                ó  € ^ RI Hp ^ RIHpHpHpHp ^ RIHp V! W4      pV! V4      p	V! W4      p
T
;'       d7    VP                  4       RJ;'       g    V! R4      ;'       d    V! 4       '       * pV'       d
   VR,          pWV
3# )z>Sudo failure handling -> (output, auth_failed, cache_cleared).N)Ú_handle_sudo_failureÚ'_invalidate_cached_sudo_on_auth_failureÚ_no_sudo_userÚ_sudo_wrong_password_failure)Úenv_var_enabledÚHERMES_INTERACTIVEuu   

âš ï¸� Sudo authentication failed â€” cached password cleared. You will be prompted again on the next sudo command.)
Útools.terminal_toolÚterminal_toolÚtools.terminal_tool_sudorF   rG   rH   rI   ÚutilsrJ   Ú_get_sudo_password_callback)r)   rA   rB   ÚttrF   rG   rH   rI   rJ   Úauth_failedÚcache_clearedÚcan_reprompts   &&&         r   Ú_sudo_annotationsrU   t   s–   € å$÷ó õ &Ù! &Ó3€FÙ.¨vÓ6€KÙ;¸GÓL€MØ ÷ ð Ø
×&Ñ&Ó(°Ð4×]Ð]¹ÐH\Ó8]÷ð á‹oÔ
ð ÷ Øð Sõ 	Tˆà Ð-Ð-r   c                ó$   € V ^8„  d   QhR\         /# ©r   r   r	   )r   s   "r   r   r   ˆ   s   € ÷ ñ ÔTWñ r   c                óî   € \        R4      ;_uu_ 4        ^ RIHp ^ RIHp T! RYY#;'       g    RVVP                  4       R7      p\        R V 4       V4      pRRR4       V#   + '       g   i     T# ; i)	zŠPlugin output-transform seam (fail-open; first string result wins).
Replacements are still subject to the output limit applied afterwards.ztransform_terminal_output hook)Úinvoke_hook)Ú_approval_tool_call_idÚtransform_terminal_outputr6   )r)   rA   Ú
returncodeÚtask_idrB   Útool_call_idc              3   óV   "  € T F  p\        V\        4      '       g   K  Vx € K!  	  R # 5i)N)Ú
isinstancer
   )r2   Úrs   & r   r4   Ú/_apply_output_transform_hook.<locals>.<genexpr>“   s   é € Ð@¡'˜Q¬Z¸¼3×-?—q’q£'ùs   ‚)Ÿ
)N)r   Úhermes_cli.lifecyclerY   Útools.approval_contextrZ   r   r9   )r)   rA   r\   r]   rB   rY   rZ   Úresultss   &&&&&   r   Ú_apply_output_transform_hookrf   ˆ   sp   € ô 
Ð0×	1Õ	1Ý4ÝAñ Ð9À7Ø)3¿]¸]ÈÐU]Ø+A×+EÑ+EÓ+GôIˆô Ñ@¡'Ó@À&ÓIˆ÷ 
2ð €M÷ 
2Ö	1ð €Mús   ”AA#Á#A4	c                ó0   € V ^8„  d   QhR\         R\         /# )r   rA   r   r	   )r   s   "r   r   r   —   s   € ÷ 7ñ 7¤ð 7¬ñ 7r   c                 ó4   € ^ RI Hp ^ RIHp V! W! 4       4      # )é    )Úget_max_bytes)Útruncate_head_tail)Útools.tool_output_limitsrj   Útools.tool_output_truncaterk   )rA   rj   rk   s   &  r   Ú_truncate_head_tailrn   —   s   € Ý6Ý=Ù˜f m£oÓ6Ð6r   c          	      ó^   € V ^8„  d   QhR\         R\        R\         R\        \         ,          /# )r   r)   r\   rA   r   )r
   r   r   )r   s   "r   r   r   �   s-   € ÷ 
ñ 
œ3ð 
¬Cð 
¼ð 
ÌHÔUXÍMñ 
r   c                ó   € \        R4      ;_uu_ 4        ^ RIHp V^ 8X  d   VP                  W4      uuRRR4       # V'       g   VP	                  WV4      uuRRR4       #  RRR4       R#   + '       g   i     R# ; i)zÕRecovery hints for well-known failure shapes (tools/terminal_hints.py);
on rc=0, warn when a pipeline tail / `|| echo` may mask an upstream
failure and the output carries strong failure indicators (advisory only).zfailure hint)Úterminal_hintsN)r   Útoolsrq   Úannotate_masked_successÚannotate_failure)r)   r\   rA   Ú	exit_noterq   s   &&&& r   Ú_failure_hintrv   �   si   € ô 
�×	Õ	Ý(Ø˜Œ?Ø!×9Ñ9¸'ÓJ÷ 
 Ò	÷ Ø!×2Ñ2°7ÈÓO÷ 
 Ò	ð ÷	 
 ñ ÷ 
 Ö	ñ ús   ”A,½A,ÁA,Á,A=	c                ó\   € V ^8„  d   QhR\         \        \        \        3,          ,          /# rW   )ÚlistrC   r
   r   )r   s   "r   r   r   ª   s#   € ÷ hñ h´d¼5ÄÄcÀ½?Õ6Kñ hr   c                óÊ  € V '       g   . #  ^ RI Hp ^ RIHp ^ RIHp \        V 4      P                  RRR7      pV! \        V 4      V! V! V4      V4      RRRR7       RTR RT  R2pRT3RT 3RT3.#   \         df    \        P                  R	RR
7       \        R4      ;_uu_ 4        \        T 4      P                  4        RRR4       M  + '       g   i     M; i. u # i ; i)zÔSpill handle so the model can read the omitted middle instead of
re-running. The collector wrote it raw; redact it with the same pass so no
secret persists unmasked on disk. On failure drop the handle (and file).©Úredact_terminal_output©Ú
strip_ansi)Úwrite_text_exclusivez	utf-8-sigÚreplace)ÚencodingÚerrorsT)ÚprivateÚ	overwriter�   z-spill redaction failed; dropping spill handler   zspill unlinkNzCOutput exceeded the capture window (head+tail shown). Full output (Ú,z chars) saved to u]    â€” search it with search_files or page it with read_file instead of re-running the command.Úoutput_total_charsÚfull_output_pathÚtruncation_note)Úagent.redactr{   Útools.ansi_stripr}   Útools.spill_safetyr~   r   Ú	read_textr   r   r   r   Úunlink)ÚpathÚtotal_charsr)   r{   r}   r~   Ú	raw_spillr#   s   &&&     r   Ú_redact_spill_filer�   ª   sï   € ÷ Øˆ	ðÝ7Ý/Ý;Ü˜“J×(Ñ(°+ÀiÐ(ÓPˆ	ñ 	œT $›ZÑ)?Á
È9Ó@UÐW^Ó)_Ø%)°TÀ)õ	MðØ'¨˜?Ð*;¸D¸6ð BXðX€Dð " ;Ð/Ð2DÀdÐ1KÐN_ÐaeÐMfÐgÐgøô ô Ü�‰ÐDÈtˆÔTÜ�N×#Õ#Ü�‹J×ÑÔ÷ $×#×#Ð#úàŠ	ð	ús*   ŒAA2 Á25C"Â'C
Ã	C"Ã
CÃ
C"Ã!C"c                ó:   € V ^8„  d   QhR\         \        ,          /# rW   )r   Údict)r   s   "r   r   r   Ä   s   € ÷ ñ ÌHÔUYÍNñ r   c           
      óú   € \        R 4      ;_uu_ 4        ^ RIHp V! WVW4R7      pV'       d,   R Uu/ uF  qwVP                  V4      bK  	  upuuRRR4       #  RRR4       R# u upi   + '       g   i     R# ; i)zverification evidence recording)Úrecord_terminal_result)r)   ÚcwdÚ
session_idr   rA   N)ÚstatusÚkindÚscopeÚcanonical_command)r   Úagent.verification_evidencer”   r   )r)   r•   r–   r\   rA   r”   ÚevidenceÚks   &&&&&   r   Ú_verification_evidencerž   Ä   sp   € Ü	Ð1×	2Õ	2ÝFÙ)°'ÈzØ4>ôOˆçÙ0`ÓaÑ0`¨1�x—|‘| A“Ò&Ñ0`Ña÷ 
3Ò	2ð ÷	 
3ñ ùò b÷ 
3Ö	2ñ ús   ”A)²A$ÁA)Á$A)Á)A:	c                ó  € V ^8„  d   QhR\         R\        R\        R\         R\         R\        \         ,          R\        \         ,          R\         R	\        \         ,          R
\        \         ,          R\        \         ,          R\         /# )r   r)   ÚresultÚenvrB   Úeffective_task_idr]   r–   Úsession_keyÚworkdirÚcommand_cwdÚapproval_noter   )r
   r’   r   r   )r   s   "r   r   r   Î   s™   € ÷ G7ñ G7ÜðG7Ü!ðG7Ü(+ðG7Ü7:ðG7ÜORðG7ä”c�]ðG7ä(0´­ðG7äDGðG7ô ”c�]ðG7ô *2´#­ðG7ô HPÔPSÅ}ðG7ô 	ñ	G7r   c           	     ó¤  € ^ RI Hp RpT;'       g    / P                  R4      '       d1   T;'       g    / P                  R4      ;'       g    \        VRR4      pV'       g   V'       d	   V! W|4       TP                  RR4      pVP                  R^ 4      p\	        WV4      w  rßp\        WWäV4      p\        V4      p^ RIHp ^ R	I	H
p V! V4      pV'       d   V! VP                  4       V 4      MRp\        W4      p\        WVV4      pRp\        R
4      ;_uu_ 4        V'       dg   V	'       d_   \        P                   P#                  \%        V4      4      \        P                   P#                  \%        V	4      4      8w  d   \%        V4      pRRR4       V
'       d'   V^‚8X  d    RV9   d   V
P'                  R4      R,           p
RVRVRR/pRV3RVP                  R4      '       d   \(        MR3.\+        VP                  R4      VP                  R4      V 4      OR\-        Y	T;'       g    T;'       g    T;'       g    RWí4      3NRT
;'       g    R3NRT;'       g    R3NRT;'       g    R3NRV'       d   RMR3NRV'       d   RMR3NpV F  w  ppVf   K  VVV&   K  	  \.        P0                  ! VRR7      #   + '       g   i     EL9; i)zETurn a raw ``env.execute`` result into the tool's JSON result string.)Úrecord_session_cwdNÚcwd_observedr•   rA   r6   r\   rz   r|   zcwd comparisonz[Command interrupted]Ú.z, then interrupted.r   ÚerrorÚenvironment_recreatedr†   r…   Úverification_evidenceÚdefaultÚapprovalÚexit_code_meaningÚhintÚsudo_auth_failedTÚsudo_cache_clearedF)Úensure_ascii)rL   r¨   r   ÚgetattrrU   rf   rn   rˆ   r{   r‰   r}   r8   r?   rv   r   Úosr�   Úrealpathr
   ÚrstripÚ_ENV_RECREATED_NOTEr�   rž   ÚjsonÚdumps)r)   r    r¡   rB   r¢   r]   r–   r£   r¤   r¥   r¦   r¨   Úobserved_cwdrA   r\   r²   r³   r{   r}   ru   Úfailure_hintÚchanged_cwdÚresult_dictÚoptional_fieldsÚkeyÚvalues   $$$$$$$$$$$               r   Úfinalize_foreground_resultrÃ   Î   sº  € õ 7ð €LØ�ˆ�"×Ñ˜.×)Ò)ØŸ˜ "×)Ñ)¨%Ó0×MÐM´G¸CÀÈÓ4Mˆß—|Ù˜;Ô5à�Z‰Z˜ "Ó%€FØ—‘˜L¨!Ó,€JÜ3DÀWÐV^Ó3_Ñ0€FÐ0Ü)¨'¸:ÐZbÓc€FÜ  Ó(€Fõ 4Ý+Ù˜Ó€F÷ AGÑ# F§L¡L£N°GÔ<ÈB€Fä$ WÓ9€IÜ  °f¸iÓH€Lð €KÜ	Ð ×	!Õ	!ßŸK¬B¯G©G×,<Ñ,<¼SÀÓ=NÓ,OÔSU×SZÑSZ×ScÑScÔdgÐhsÓdtÓSuÔ,uÜ˜lÓ+ˆK÷ 
"÷ ˜ sÔ*Ð/FÈ&Ô/PØ%×,Ñ,¨SÓ1Ð4IÕIˆà˜V [°*¸gÀtÐL€Kð 
�ÐØ	 ¸¿¹ÐD[×9\Ò9\Õ"5ÐbfÐgð.ô 
˜FŸJ™JÐ'9Ó:¸F¿J¹JÐG[Ó<\Ð^eÓ	fð.ð 
!Ô"8Ø *×"YÐ"Y°×"YÐ"YÐ;L×"YÐ"YÐPYØó# ð 	!ð	.ð 
�]×*Ð* dÐ+ð.ð 
˜i×/Ð/¨4Ð0ð.ð 
�×%Ð% Ð&ð.ð 
×%5™T¸4Ð@ð.ð 
×'9™t¸tÐDð.€Oó &‰
ˆˆUØÔØ$ˆK˜Óñ &ô �:Š:�k°Ô6Ð6÷9 
"×	!Ð	!ús   ÄJ>Ä0AJ>Ê>K	c                óÎ   € V ^8„  d   Qh/ ^ \         9   d   \        \        \        3,          ;R&   ^\         9   d,   \        \        \        \        \        3,          3,          ;R&   # )r   r   r:   )Ú__conditional_annotations__r’   r   r
   )r   s   "r   r   r      sT   € ÷ ñ ÷>ò ”Dœœc˜•Nñ ñ?÷Hò ”dœ3¤¤S¬# X¥Ð.Õ/ñ òIr   )ÚgrepÚegrepÚfgrepÚrgÚagÚack)ÚdiffÚ	colordiff)ÚtestÚ[)rÅ   Ú__doc__rº   Úloggingr¶   r7   r   Ú
contextlibr   Úpathlibr   Útypingr   r   Ú	getLoggerr   r   r   r$   r:   r¹   r?   rU   rf   rn   rv   r�   rž   rÃ   r   )rÁ   rÅ   s   0@r   Ú<module>rÖ      s”  øðöó Û Û 	Û 	Û Ý %Ý ß  à	×	Ò	Ð0Ó	1€ð ô8ó ð8ð Ð&ØÐOØÐTØÐEØÐHØÐ^ØÐ>ØÐXØÐPØÐ+ØÐ,ð&Ð ó õð,3Ù>kÓlÑ>k°sˆQÐ1Ð2Ò2Ñ>kÑlð3áDYÓZÑDY¸SˆQÐ7Ð8Ò8ÑDYÑZð3ñ UbÓbÑTaÈSˆQÐGÐHÒHÑTaÑbð3ð ˆQÐYÐZØ
ˆQÐ(¨!Ð-HØÐEÀrÐK`ðbà	ˆAÐ]Ð^ñ3Ð ó ð$ð õAõ0.õ(õ7õ
õhõ4÷G7ùòQ mùÚZùÚbs   Á5C:Â	C?ÂD