+
    lHàjg  ã            &       óž  a € Ra t>0 t R t^ RI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Ht ^ RIHt ^ RIHt Rt ^ RIt]P0                  ! ]4      t]! RRR	7      t] ^ k R
 R lt^ RIHtHtH t H!t!H"t"H#t# R R lt$R R lt%R R lt&RRbR lR 3RRbR lR 3RRbR lR 3RRbR lR 3/t'R R  lt(RbR! R" llt)R# R$ lt*Rct+R%t,R& R' lt-RdR) R* llt.ReR+ R, llt/R- R. lt0R/ R0 lt1R1 R2 lt2RbR3 R4 llt3RbR5 R6 llt4]R7 R8 l4       t5RbR9 R: llt6R; R< lt7R=R(R>R?R@RARBRCRDRARERF. RfOR>RG/RHRARERFR(RI.R>RJ/RKRARER>RL/RMRARER>RN/RORARER>RP/RQRARRR>RSRTRARBRCRDRARERF. RfO/RKRARER>RU/RORARER>RV/RMRARER>RW//RXRD.RYRZ///RXRH.//t8RgRhRiRj/t9R[ R\ lt:^ R]IH;t;H<t< ];Pz                  ! R(R(]8R^ ]5R_]:R`7       R#   ] d    Rt ^ RIt ELt  ] d      ELi ; ii ; i)ka2  Memory Tool - persistent curated memory (MEMORY.md = agent notes, USER.md = user
profile). Both enter the system prompt as a FROZEN snapshot at session start;
mid-session writes hit disk but never change the prompt (prefix cache intact).
Single `memory` tool: add/patch/remove or a batch `operations` list.N)Ú
ContextVar©ÚPath©Úget_hermes_home)ÚDictÚAnyÚListÚOptionalÚTuple)Úis_truthy_value)Úno_cache_check_fnÚmemory_surface_flags©Údefaultc                ó$   € V ^8„  d   QhR\         /# ©é   Úreturnr   )Úformats   "Ú6/home/ubuntu/.hermes/hermes-agent/tools/memory_tool.pyÚ__annotate__r   &   s   € ÷ *ñ *œñ *ó    c                 ó$   € \        4       R,          # )zUProfile-scoped memories dir, resolved per call (HERMES_HOME may switch after import).Úmemoriesr   © r   r   Úget_memory_dirr   &   s   € äÓ˜zÕ)Ð)r   )ÚENTRY_DELIMITERÚFAILURE_CLASSÚMEMORY_BLOCK_HEADERSÚPATCH_DROP_HINTÚMemoryStoreÚ_scan_memory_contentc                ó$   € V ^8„  d   QhR\         /# r   )r!   )r   s   "r   r   r   /   s   € ÷ ñ œKñ r   c            	     ó<  €  ^ RI Hp  V ! 4       ;'       g    / p\        V4      p\        V4      w  r4\	        \        VP                  RR4      4      \        VP                  RR4      4      W4R7      pVP                  4        V#   \         d    \	        4       p L)i ; i)zçFresh on-disk MemoryStore with configured limits/flags for contexts with no live
agent (gateway, Desktop, ``/memory``) so approvals enforce the SAME caps as
``agent_init``. Falls back to defaults if config can't load; never raises.)Úload_configÚmemory_char_limiti˜  Úuser_char_limiti_  ©Úmemory_enabledÚuser_profile_enabled)	Úhermes_cli.configr%   Úget_builtin_memory_configÚget_builtin_memory_store_flagsr!   ÚintÚgetÚ	ExceptionÚload_from_disk)r%   ÚconfigÚmem_cfgr)   r*   Ústores         r   Úload_on_disk_storer5   /   s�   € ðÝ1Ù“×$Ð$ "ˆÜ+¨FÓ3ˆÜ/MÈfÓ/UÑ,ˆÜœC §¡Ð,?ÀÓ FÓGÌÈWÏ[É[ÐYjÐlpÓMqÓIrØ+9ôfˆð 
×ÑÔØ€Løô ô Ü“Šðús   ‚B –AB ÂBÂBc                ót   € V ^8„  d   QhR\         R\        \        \        3,          R\        \        ,          /# )r   r4   Úpayloadr   )r!   ÚdictÚstrr   r
   )r   s   "r   r   r   @   s3   € ÷ Uñ U¤ð U´d¼3Ä¸8µnð UÌÔRUÍñ Ur   c                ó~  € VP                  RR4      pVP                  R4      R8X  dn   V P                  W!R,          4      pVP                  R4      '       d>   \        VR,          VR,          4       UUu. uF  w  rEVf   TM/ VCR	V/CNK  	  uppVR&   MrVP                  R4      \        9   dW   T P	                  Y!P                  R
4      ;'       g    RVR,          4      pVP                  R4      '       d   VR	,          VR	&   MR# VP                  R4      '       d   R# \
        P                  ! VRR7      # u uppi )aU  Record on each staged replace/remove the FULL entry its old_text selects now. Approval
then applies to exactly the entry the approver reviewed and refuses if it changed:
re-running the old_text search at approve time could hit a newer entry that still
contains it. Returns the JSON error when the search fails now, as the direct write would.ÚtargetÚmemoryÚactionÚbatchÚ
operationsÚsuccessÚmatched_entriesNÚmatched_entryÚold_textÚ F©Úensure_ascii)r/   Úresolve_batch_entriesÚzipÚ_BG_DELETE_ACTIONSÚresolve_entryÚjsonÚdumps)r4   r7   r;   ÚresultÚopÚentrys   &&    r   Ú_pin_matched_entriesrP   @   s!  € ð
 �[‰[˜ 8Ó,€FØ‡{�{�8Ó Ô'Ø×,Ñ,¨V¸\Õ5JÓKˆØ�:‰:�i× Ò ä69¸'À,Õ:OÐQWÐXiÕQjÔ6kô%mÙ6k©¨ð ,1ª=¡RÐ>\ÀÐ>\À_ÐV[Ñ>\Ò%\Ù6kò%mˆG�LÑ!øà	�‰�XÓ	Ô"4Ô	4Ø×$Ñ$ V¯[©[¸Ó-D×-JÐ-JÈÈGÐT\ÕL]Ó^ˆØ�:‰:�i× Ò Ø'-¨oÕ'>ˆG�OÑ$øáØ—:‘:˜i×(Ò(ˆ4ÐT¬d¯jªj¸ÈeÔ.TÐTùó%ms   Á5D9c                óŒ   € V ^8„  d   QhR\         R\        R\        R\        \        \        3,          R\        \        ,          /# )r   r4   ÚsummaryÚdetailr7   r   )r!   r9   r8   r   r
   )r   s   "r   r   r   T   sA   € ÷ *ñ *œ+ð *´ð *¼Sð *Ì4ÔPSÔUXÐPXÍ>ð *Ô^fÔgjÕ^kñ *r   c           
     ó4  €  ^ RI Hp TP                  TP                  YR7      pTP
                  '       d   R# TP                  '       d.   \        P                  ! R4       \        TP                  RR7      # \        Y4      ;pe   T# \        P                  ! R4       TP                  TP                  Y1 RTR	,           2TP                  4       R
7      p\        P                  ! RRRRRTR,          RTP                  /RR7      #   \         d     R# i ; i)z”JSON tool-result string when the write must NOT proceed (blocked or staged
for approval), None to proceed. Fails open if the gate module can't load.©Úwrite_approvalN)Úinline_summaryÚinline_detailÚgate_refusedF©r@   Ústagedú: :Néx   N©rR   Úoriginr@   TÚ
pending_idÚidÚmessagerE   )ÚtoolsrV   r0   Úevaluate_gateÚMEMORYÚallowÚblockedr   ÚsetÚ
tool_errorrb   rP   Ústage_writeÚcurrent_originrK   rL   )r4   rR   rS   r7   ÚwaÚdecisionÚ	unmatchedÚrecords   &&&&    r   Ú_gate_or_stagerp   T   sú   € ðÝ.ð ×Ñ §	¡	¸'ÐÓX€HØ‡~‡~€~ÙØ××ÐÜ×Ò˜.Ô)Ü˜(×*Ñ*°EÔ:Ð:Ü)¨%Ó9Ð9ˆ	ÒFØÐÜ×Ò�hÔØ�^‰^˜BŸI™I w¸)À2ÀfÈTÅlÀ^Ð8TÐ]_×]nÑ]nÓ]pˆ^Óq€FÜ�:Š:�y $¨°$¸ÀfÈTÅlÐT]Ð_g×_oÑ_oÐpØ#(ô*ð *øô ô Úðús   ‚D ÄDÄDÚaddc                 ó$   € V P                  W4      # ©N)rq   ©r4   r;   ÚcontentrC   rO   s   &&&&&r   Ú<lambda>rv   l   s   € ÀÇÁÈ6ÔA[r   c                 ó$   € R V  2T;'       g    R3# )zadd to rD   r   ©Úlabelru   rC   s   &&&r   rv   rv   m   s   € °¸°wÐ.?ÀÇÀÈBÑ-Or   Úreplacec                 ó&   € V P                  WW$4      # rs   )rz   rt   s   &&&&&r   rv   rv   n   s   € ÀUÇ]Á]ÐSYÐelÔEtr   c                 ó   € R V  2RV RV 23# )zreplace in úentry matching: z
whole entry becomes: r   rx   s   &&&r   rv   rv   o   s$   € °KÀ¸wÐ2GØ4DÀXÀJÐNeÐfmÐenÐ2oñ2qr   Úremovec                 ó&   € V P                  WV4      # rs   )r~   rt   s   &&&&&r   rv   rv   q   s   € ÀEÇLÁLÐQWÐchÔDir   c                 ó$   € R V  2T;'       g    R3# )zremove from rD   r   rx   s   &&&r   rv   rv   r   s   € °<À¸wÐ1GÈÏÈÐUWÑ0Xr   Úpatchc                 ó&   € V P                  WW$4      # rs   )r�   rt   s   &&&&&r   rv   rv   s   s   € À5Ç;Á;ÈvÐahÔCpr   c                 ó$   € R V  2RV RV RV R23# )z	patch in r}   z
span 'z' becomes: z (rest of the entry is kept)r   rx   s   &&&r   rv   rv   t   s6   € °)¸E¸7Ð0CØ2BÀ8À*ÈHÐU]ÐT^Ð^iÐjqÐirð sNð 1Nñ0Or   c                óR   € V ^8„  d   QhR\         \        \        3,          R\        /# )r   rN   r   ©r8   r9   r   )r   s   "r   r   r   y   s"   € ÷ !ñ !”tœC¤˜H•~ð !¬#ñ !r   c                 ó  € T ;'       g    / p V P                  R R4      V P                  R4      ;'       g    V P                  R4      ;'       g    RV P                  RR4      r2pVR8X  d   RV 2# VR8X  d
   R	V R
V R2# RV RV 2# )r=   Ú?ru   Únew_textrD   rC   r~   z
- remove: r�   z- patch span 'z' -> 'z' (rest of the entry is kept)z- r\   ©r/   )rN   Úactru   Úolds   &   r   Ú_batch_op_linerŒ   y   sš   € Ø	�ˆˆr€BØŸ™˜x¨Ó-¨r¯v©v°iÓ/@×/\Ð/\ÀBÇFÁFÈ:ÓDV×/\Ð/\ÐZ\Ð^`×^dÑ^dÐeoÐqsÓ^t�#€CØ
ˆh„Ø˜C˜5Ð!Ð!Ø
ˆg„~Ø ˜u F¨7¨)Ð3PÐQÐQØ�ˆu�B�w�iÐ Ð r   c                óü   € V ^8„  d   QhR\         R\        R\        R\        \        ,          R\        \        ,          R\        \        \        \        \
        3,          ,          ,          R\        \        ,          /# )r   r4   r=   r;   ru   rC   r?   r   )r!   r9   r
   Úlistr8   r   )r   s   "r   r   r   ƒ   sk   € ÷ 	jñ 	jœ[ð 	j´#ð 	j¼sð 	jÌXÔVYÍ]ð 	jÜ (¬¥ð	jÜ;CÄDÌÌcÔSVÈhÍÕDXÕ;Yð	jÜemÔnqÕerñ	jr   c                óò   € VR8X  d   RMRpVe:   \        V R\        V4       RV 2RP                  R V 4       4      RR	R
VRV/4      # \        V .\        V,          ^,          ! WcV4      ORVR
VRVRV/N5!  # )zMGate one mutating op, or (``operations`` set) a whole batch as a single unit.Úuserzuser profiler<   zapply z
 op(s) to Ú
c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5irs   ©rŒ   ©Ú.0rN   s   & r   Ú	<genexpr>Ú$_apply_write_gate.<locals>.<genexpr>‰   s   é € Ð'PÁZ¸r¬°r×(:Ð(:ÃZùó   ‚r=   r>   r;   r?   ru   rC   )rp   ÚlenÚjoinÚ_STORE_ACTIONS)r4   r=   r;   ru   rC   r?   ry   s   &&&&&& r   Ú_apply_write_gaterœ   ƒ   s¨   € ð %¨Ô.‰N°H€EØÒÜ˜e v¬c°*«oÐ->¸jÈÈÐ%PØ"Ÿi™iÑ'PÁZÓ'PÓPØ'¨°(¸FÀLÐR\Ð]ó_ð 	_ô ˜%ð j¤.°Õ"8¸Ö";¸EÈHÓ"Uð jØ# V¨X°v¸yÈ'ÐS]Ð_gÐhójð jr   c                ó:   € V ^8„  d   QhR\         \        ,          /# r   ©r
   r9   )r   s   "r   r   r   �   s   € ÷ ñ ÄXÌcÅ]ñ r   c                ó¶  € VR8X  d,   V'       g$   \         P                  ! R4       \        RRR7      # VR9   dg   V'       g_   \         P                  ! R4       \        P                  ! RRR	R
V RV RV R2RV P                  V4      RV P                  V4      /RR7      # VR8X  d3   V'       g+   \         P                  ! R4       \        R\         2RR7      # R# )uõ   Validate BEFORE the gate so an invalid write is rejected now, not at approve time.
Missing ``old_text`` is recoverable (it can't be schema-required â€” needs a combinator
the Codex backend rejects): return the inventory plus a retry instruction.rq   Úmissing_contentz%Content is required for 'add' action.FrZ   r�   Úmissing_old_textr@   ÚerrorÚ'z=' needs old_text -- a short unique substring of the entry to z!. None was provided. Reissue the z? with old_text set to part of one of the current_entries below.Úcurrent_entriesÚusagerE   zMcontent (the new text for the old_text span) is required for 'patch' action. N)r~   r�   )r   rh   ri   rK   rL   Ú_entries_forÚ_usager    )r4   r=   r;   ru   rC   s   &&&&&r   Ú_validate_single_opr¨   �   sì   € ð �„ŸwÜ×ÒÐ+Ô,ÜÐAÈ5ÔQÐQØÐ$Ô$¯XÜ×ÒÐ,Ô-Ü�zŠzØ�uØ˜˜&˜ð "Ø"˜8Ð#DÀVÀHð MIðJð ˜u×1Ñ1°&Ó9¸7ÀEÇLÁLÐQWÓDXðZð
 inôoð 	oð �Ô§Ü×ÒÐ+Ô,ÜÐiÜ,Ð-ð/Ø8=ô?ð 	?ár   zÙ'replace' is not available; use 'patch'. old_text is the exact span to change and content is its new text; the rest of the entry is kept. To rewrite a whole entry, set old_text to the whole entry. Nothing was written.c                óŠ   € V ^8„  d   QhR\         \        \        3,          R\        \         \        \        3,          ,          /# )r   r7   r   )r8   r9   r   rŽ   )r   s   "r   r   r   ­   s3   € ÷ Pñ PœT¤#¤s (�^ð P´´T¼#¼s¸(µ^Õ0Dñ Pr   c                óâ   € V P                  R4      R8X  d   V P                  R4      ;'       g    . MV .pV Uu. uF*  q";'       g    / P                  R4      \        9   g   K(  VNK,  	  up# u upi )zLThe replace/remove ops of a staged memory payload, single-op or batch shape.r=   r>   r?   )r/   rI   )r7   ÚopsrN   s   &  r   Údestructive_opsr¬   ­   s^   € à/6¯{©{¸8Ó/DÈÔ/Oˆ7�;‰;�|Ó$×*Ð*¨øÐV]ÐU^€CÙÓO™�2§  r§¡¨xÓ 8Ô<NÑ N�BˆB™ÑOÐOùÒOs   ¹A,ÁA,Á#A,r<   c                ó:   € V ^8„  d   QhR\         \        ,          /# r   rž   )r   s   "r   r   r   ³   s   € ÷ (@ñ (@Ü.6´s­mñ(@r   c                ó¶  € ^ RI Hp V! 4       '       g   R# Ve	   RRRVRV/M	RVRVRVRV/p\        V4      '       g   R# Ve   R	P                  R
 V 4       4      M\	        RVRVRV/4      p \        W4      ;p	e   V	# ^ RIHp
 \        P                  ! R4       T
P                  V
P                  TRVe   RMT RV RV 2R,          V
P                  4       R7      p\        P                  ! RRRRRRRVR,          RRVe   RMT R2/RR7      #   \         d>    \         P#                  RRR7       \        P                  ! R4       \%        RRR 7      u # i ; i)!uå  Fail-closed operation gate for unattended background-review forks (#105921): ``add``
stays available (it is all any review prompt asks for), while ``patch``/``remove`` â€”
single or inside a batch â€” are never applied unattended. The op is staged in the pending
store instead of merely denied: the fork's own review summary is never published back, so
a plain denial would drop the consolidation request with no surfacing path at all. A
staging failure fails closed to a plain denial.)Úis_unattended_reviewNr=   r>   r;   r?   ru   rC   z; c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5irs   r“   r”   s   & r   r–   Ú*_background_delete_gate.<locals>.<genexpr>Ä   s   é € Ð@±Z¨rœ r×*Ð*³Zùr˜   rU   r[   z!background review consolidation (z on z): :NéÈ   Nr^   r@   TÚproposal_stagedr`   ra   rb   zIBackground review may not delete memory entries unattended. The proposed ue    was staged for your approval â€” review it with /memory pending (approve to apply, discard to drop).FrE   z8Failed to stage background-review consolidation; denying©Úexc_inforY   zsBackground review may not delete memory entries ('patch'/'remove', including in a batch); 'add' is still available.rZ   )Útools.skill_provenancer¯   r¬   rš   rŒ   rP   rc   rV   r   rh   rj   re   rk   rK   rL   r0   ÚloggerÚwarningri   )r4   r=   r?   r;   ru   rC   r¯   r7   rS   rn   rl   ro   s   &&&&&&      r   Ú_background_delete_gater¹   ³   sª  € õ <á×!Ò!ÙàÒ(ð ˜' 8¨V°\À:ÑNà˜& (¨F°I¸wÈ
ÐT\Ð]ð ô ˜7×#Ò#ÙØDNÒDZˆd�i‰iÑ@±ZÓ@Ô@Ü! 8¨V°YÀÈÐU]Ð"^Ó_ð ð@Ü-¨eÓ=Ð=ˆIÒJØÐÝ.Ü×Ò˜(Ô#Ø—‘Ø�I‰I�wØ8ÀJÒDZ¹Ð`fÐ8gð hØ!˜( # f Xð/Ø04õ6à×$Ñ$Ó&ð	  ó (ˆô
 �zŠzØ�t˜X tÐ->ÀÀlÐTZÐ[_ÕT`ØÐcØ&0Ò&<™7À&ÐIð J^ð^ð
ð
 ôð 	øô ô @Ü�‰ÐQÐ\`ˆÔaÜ×Ò˜.Ô)Üð0Ø9>ô@ò 	@ð@ús   Á-D Á>BD ÄAEÅEc                ó  € V ^8„  d   QhR\         R,          R\         R\         R,          R\         R,          R\         R,          R\        \        \        \         \        3,          ,          ,          R\        \
        ,          R	\         /# )
r   r=   Nr;   ru   rC   rˆ   r?   r4   r   )r9   r
   rŽ   r8   r   r!   )r   s   "r   r   r   Þ   st   € ÷ ñ œ˜d�
ð ´3ð ÌCÐRVÍJð ÔilÐosÕisð Ü �*ðÜ9AÄ$ÄtÌCÔQTÈHÅ~ÕBVÕ9Wðä¤Õ,ðä8;ñr   c           	     ó4  € Vf   \        RRR7      # \        P                  ! R4      p \        WW#WEV4      w  r‰VR8X  d   RM\        P                  ! 4       p
\        P
                  ! V4       ^ RIHp V! WWŠR7       V	#   \        P
                  ! T4       i ; i)	z¬Tool entry point; returns a JSON string. Single op (action + content/old_text)
or batch (``operations``, atomic against the final budget). ``new_text``
aliases ``content``.zJMemory is not available. It may be disabled in config or this environment.FrZ   Úotherr@   Únone)Úrecord_builtin_memory_call)ÚoutcomeÚfailure_class)ri   r   rh   Ú_memory_toolr/   ÚresetÚ,hermes_cli.observability.shared_metrics_loopr¾   )r=   r;   ru   rC   rˆ   r?   r4   Útokenr¿   rM   rÀ   r¾   s   &&&&&&&     r   Úmemory_toolrÅ   Þ   s‰   € ð ‚}ÜÐfÐpuÔvÐvÜ×Ò˜gÓ&€Eð#Ü& v°wÈ(Ð`eÓf‰ˆØ")¨YÔ"6™¼M×<MÒ<MÓ<Oˆä×Ò˜EÔ"ÝWÙ˜v¸7Õ`Ø€Møô 	×Ò˜EÕ"ús   ©.A? Á?Bc                ót   € V ^8„  d   QhR\         \        \        3,          R\        \        \        3,          /# )r   rM   r   )r8   r9   r   Útuple)r   s   "r   r   r   ñ   s.   € ÷ fñ f”Tœ#œs˜(•^ð f¬¬c´3¨h­ñ fr   c                 óh   € V P                  R 4      '       d   R MR\        P                  ! V RR7      3# )r@   ÚfailedFrE   )r/   rK   rL   )rM   s   &r   Ú_appliedrÊ   ñ   s)   € ØŸ™ I×.Ò.‰I°H¼t¿zºzÈ&Ð_dÔ?eÐeÐer   c                óR   € V ^8„  d   QhR\         R\        \         \         3,          /# )r   rb   r   )r9   rÇ   )r   s   "r   r   r   õ   s"   € ÷ :ñ :”cð :œe¤C¬ H�oñ :r   c                 óL   € \         P                  ! R 4       R\        V RR7      3# )Úinvalid_argsÚrejectedFrZ   )r   rh   ri   )rb   s   &r   Ú_invalidrÏ   õ   s"   € Ü×Ò�nÔ%Ø”z '°5Ô9Ð9Ð9r   c                óF   € V ^8„  d   QhR\         \        \        3,          /# r   )rÇ   r9   )r   s   "r   r   r   ú   s#   € ÷ 'Qñ 'QÔTYÔZ]Ô_bÐZbÕTcñ 'Qr   c                óD  € V'       g   V'       d   Tp\        WaV4      pVe   R\        P                  ! V4      3# V'       d±   \        V\        4      '       g   \        R4      # \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        \        4      # \        W`WQ4      pVe   RV3# \        VRVRRV4      p	V	e   RV	3# \        VP                  W4      4      # V '       g   V'       g   \        R4      # V R	8X  d   \        \        4      # V \        9  d   \        R
V  R24      # \        W`WV4      ;'       g$    \        W`RWV4      ;'       g    \        W`WV4      p
V
e   RV
3# \        \        V ,          ^ ,          ! WaW#4      4      # )zX``(outcome, result_json)``: ``rejected`` when refused or held before touching the store.NrÎ   zCoperations must be a list of {action, content?, old_text?} objects.c              3   óz   "  € T F1  p\        V\        4      ;'       d    VP                  R 4      R8H  x € K3  	  R# 5i)r=   rz   N)Ú
isinstancer8   r/   r”   s   & r   r–   Ú_memory_tool.<locals>.<genexpr>  s2   é € Ð[ÑPZÈ"Œz˜"œdÓ#×EÐE¨¯©¨xÓ(8¸IÑ(EÔEÓPZùs   ‚;ž;TFr>   zjMissing required parameter: provide 'action' (add/patch/remove) or 'operations' (batch list). Got neither.rz   zUnknown action 'z'. Use: add, patch, remove)Ú_memory_target_errorrK   rL   rÓ   rŽ   rÏ   ÚanyÚ_REPLACE_REMOVEDr¹   rœ   rÊ   Úapply_batchr›   r¨   )r=   r;   ru   rC   rˆ   r?   r4   Útarget_errorÚdeniedÚgate_resultÚinvalids   &&&&&&&    r   rÁ   rÁ   ú   s—  € ÷ —xØˆÜ'¨°zÓB€LØÒØœ4Ÿ:š: lÓ3Ð3Ð3ßÜ˜*¤d×+Ò+ÜÐaÓbÐbß‹3Ñ[ÑPZÓ[�3�3Š3Ñ[ÑPZÓ[×[Ò[ÜÔ,Ó-Ð-Ü(¨¸
ÓKˆØÒØ˜vÐ%Ð%ä'¨¨w¸ÀÀdÈJÓWˆØÒ"Ø˜{Ð*Ð*Ü˜×)Ñ)¨&Ó=Ó>Ð>÷
 Ÿ*Üð9ó
ð 	
ð �ÔÜÔ(Ó)Ð)Ø”^Ô#ÜÐ*¨6¨(Ð2LÐMÓNÐNÜ" 5°&À8ÓL÷ Nð NÜ)¨%¸¸vÐPXÓY÷Nð Nä# E°6ÀHÓMð ð ÒØ˜7Ð"Ð"Ü”N 6Õ*¨1Ö-¨e¸WÓOÓPÐPr   c                óŠ   € V ^8„  d   QhR\         \        \        \        3,          ,          R\        \        \        3,          /# ©r   r2   r   )r
   r8   r9   r   )r   s   "r   r   r   $  s0   € ÷ 8ñ 8¤h¬t´C¼°H­~Õ&>ð 8Ì$ÌsÔTWÈxÍ.ñ 8r   c                ó   € V f    ^ RI Hp V! 4       p \        V \        4      '       d   V P                  R4      MRp\        V\        4      '       d   V# / #   \         d    \        P	                  RRR7       / u # i ; i)u®   Normalized ``memory`` config section ({} when missing/malformed â†’ flags default to
enabled). ``agent_init`` reads the same section so availability and store cannot diverge.N)Úload_config_readonlyz-Could not read memory config for availabilityTr´   r<   )r+   rà   r0   r·   ÚdebugrÓ   r8   r/   )r2   rà   Úsections   &  r   r,   r,   $  sv   € ð ‚~ð	Ý>Ù)Ó+ˆFô '1°¼×&>Ò&>ˆf�j‰j˜Ô"ÀD€GÜ  ¬$×/Ò/ˆ7Ð7°RÐ7øô	 ô 	Ü�L‰LÐHÐSWˆLÔXØŠIð	ús   †A Á$A=Á<A=c                óŠ   € V ^8„  d   QhR\         \        \        \        3,          ,          R\        \
        \
        3,          /# rÞ   )r
   r8   r9   r   rÇ   Úbool)r   s   "r   r   r   2  s7   € ÷ tñ t¬8´D¼¼c¸µNÕ+Cð tÌuÔUYÔ[_ÐU_ÕO`ñ tr   c                ó~   a€ \        V 4      o\        ;QJ d    . V3R lR 4       F  NK  	  5# ! V3R lR 4       4      # )zGReturn ``(memory_enabled, user_profile_enabled)`` from resolved config.c              3   ó\   <"  € T F!  p\        SP                  V4      R R7      x € K#  	  R# 5i)Tr   N)r   r/   )r•   Úkrâ   s   & €r   r–   Ú1get_builtin_memory_store_flags.<locals>.<genexpr>5  s%   øé € ÐsÑHrÀ1” §¡¨Q£¸×>Ñ>ÓHrùs   ƒ),r(   )r,   rÇ   )r2   râ   s   &@r   r-   r-   2  s1   ø€ ä'¨Ó/€GßŒ5ÔsÑHrÓs�5Ðsˆ5ÔsÑHrÓsÓsÐsr   c                ó$   € V ^8„  d   QhR\         /# r   )rä   )r   s   "r   r   r   9  s   € ÷  ñ  ¤4ñ  r   c                 óž   € \         P                  R4       \        4       p \         P                  V 4       V ^ ,          ;'       g
    V ^,          # )zGSnapshot store flags and report whether the built-in tool is available.N)Ú_memory_surface_flagsrh   r-   )Úflagss    r   Úcheck_memory_requirementsrí   8  s>   € ô ×Ñ˜dÔ#Ü*Ó,€EÜ×Ñ˜eÔ$Ø��8×Ð�u˜Q•xÐr   c          
      óÌ   € V ^8„  d   QhR\         R\        R,          R\        \        \        \        3,          ,          R,          R\        \        \        3,          R,          /# )r   r4   r;   Nr?   r   )r!   r9   rŽ   r8   r   )r   s   "r   r   r   A  sU   € ÷ tñ tÜðtÜ # d¥
ðtÜ8<¼TÄ#ÄsÀ(½^Õ8LÈtÕ8Sðtä	Œ#Œsˆ(…^�dÕñtr   c                óZ  € Vf   \         P                  ! R4       RRRR/# \        V\        4      '       d   VR9  d-   ^ RIHp \         P                  ! R4       RRRV! R	V R
24      /# \        V\        4      '       dh   \        V^4       FW  w  rE\        V\        4      '       g   K  VP                  R4      RV39  g   K7  \         P                  ! R4       RRRRV R2/u # 	  V P                  V4      '       d   R# VR8X  d   RMRp\         P                  ! R4       RRRRV R2RV/# )zJValidate one explicit store before writing, staging, or replaying a batch.NrÍ   r@   Fr¢   zÏMissing required target. Retry with target='memory' or target='user' at the top level. For a batch, remove target from every operation; use separate calls for different stores. Nothing was written or staged.r�   )Ú_bound_error_textzInvalid memory target 'z'. Use 'memory' or 'user'.r;   z
Operation z¢ names a different target than the one at the top level. One call writes one store: retry with separate calls for different stores. Nothing was written or staged.zUSER.mdz	MEMORY.mdÚdisabledz	Built-in z& writes are disabled in memory config.>   r�   r<   )r   rh   rÓ   r9   Útools.registryrð   rŽ   Ú	enumerater8   r/   Útarget_enabled)r4   r;   r?   rð   ÚindexrN   ry   s   &&&    r   rÕ   rÕ   A  s@  € ð ‚~Ü×Ò˜.Ô)Ø˜5 'ð-ð/ð 	/ô �fœc×"Ò" fÐ4FÔ&FÝ4Ü×Ò˜.Ô)Ø˜5ØÑ*Ð-DÀVÀHÐLfÐ+gÓhðjð 	jä�*œd×#Ò#Ü" :¨qÖ1‰IˆEô ˜"œd×#Ô#¨¯©¨xÓ(8ÀÀvÀÖ(NÜ×!Ò! .Ô1Ø! 5¨'Ø   ð (5ð 5ð7ò 7ñ 2ð ×Ñ˜F×#Ò#ÙØ 6Ô)‰I¨{€EÜ×Ò�jÔ!Ø�u˜g¨°5°'Ð9_Ð'`ÐbjÐlrÐsÐsr   c                ó€   € V ^8„  d   QhR\         \        \        3,          R\        R\         \        \        3,          /# )r   r7   r4   r   )r8   r9   r   r!   )r   s   "r   r   r   a  s7   € ÷ Cñ C¤$¤s¬C x¥.ð C¼ð CÌÌcÔSVÈhÍñ Cr   c           	     ór  € V P                  R4      V P                  R4      r2\        WV P                  R4      4      pVe   V# \        ;QJ d%    R \        V 4       4       F  '       g   K   RM	  RM! R \        V 4       4       4      '       d   RRRR	/# VR
8X  d+   TP	                  Y0P                  R4      ;'       g    . 4      # V\
        9  d   RRRRV R2/# \
        V,          ^ ,          ! YV P                  R4      ;'       g    RV P                  R4      ;'       g    RV P                  R4      4      # )aA  Replay a staged write against the store, bypassing the gate (/memory approve). A
replace/remove applies to exactly its pinned ``matched_entry`` or is refused; a record
staged before pinning has no verifiable target, so it is refused rather than replayed by
old_text (which could hit a newer entry the approver never saw).r=   r;   r?   c              3   óL   "  € T F  qP                  R 4      '       * x € K  	  R# 5i)rB   Nr‰   r”   s   & r   r–   Ú'apply_memory_pending.<locals>.<genexpr>j  s   é € Ð
JÑ1I¨2�v‰v�oÓ&×&Ñ&Ó1Iùs   ‚"$TFr@   r¢   z…This destructive pending write predates entry pinning and cannot be verified; nothing was applied. Reject it and recreate the change.r>   zUnknown staged action 'z'.ru   rD   rC   rB   )r/   rÕ   rÖ   r¬   rØ   r›   )r7   r4   r=   r;   rÙ   s   &&   r   Úapply_memory_pendingrú   a  s  € ð
 —[‘[ Ó*¨G¯K©K¸Ó,AˆFÜ'¨°w·{±{À<Ó7PÓQ€LØÒØÐß
ƒsÑ
J´ÀÔ1IÓ
J‡s‡s‚sÑ
J´ÀÔ1IÓ
J×JÒJØ˜5 'ð ,oð pð 	pà�ÔØ× Ñ  ¯©°\Ó)B×)HÐ)HÀbÓIÐIØ”^Ô#Ø˜5 'Ð-DÀVÀHÈBÐ+OÐPÐPÜ˜&Õ! !Ö$ U°G·K±KÀ	Ó4J×4PÐ4PÈbÐRY×R]ÑR]Ð^hÓRi×RoÐRoÐmoØ%,§[¡[°Ó%AóCð Cr   ÚnameÚdescriptionuH  Save durable facts to persistent memory that survive across sessions. Memory is injected into every future turn, so keep entries compact and high-signal.

HOW: make ALL your changes to one target in ONE call via an 'operations' array (each item: {action, content?, old_text?}). The batch applies atomically and the char limit is checked only on the FINAL result â€” so a single call can remove/patch stale entries to free room AND add new ones, even when an add alone would overflow. The response reports current/limit chars and confirms completion; one batch call finishes the update, so don't repeat it. Use the bare action/content/old_text fields only for a single lone change.

WHEN: only for facts that apply to EVERY session regardless of task: who the user is, stable environment facts, standing conventions with no task home. Anything learned while doing a task (procedures, pitfalls, and the user's preferences and corrections for that kind of work) belongs in the task's skill via skill_manage, where it loads only when relevant; memory is injected into every turn and must stay small.

IF FULL: an add is rejected with the current entries shown. Reissue as ONE batch that removes or shortens enough stale entries and adds the new one together.

TARGETS: 'user' = who the user is (name, role, preferences, style). 'memory' = your notes (environment, conventions, tool quirks, lessons).

SKIP: trivial/obvious info, easily re-discovered facts, raw data dumps, task progress, completed-work logs, temporary TODO state (use session_search for those). Reusable procedures belong in a skill, not memory.Ú
parametersÚtypeÚobjectÚ
propertiesr=   ÚstringÚenumzFThe action to perform (single-op shape). Omit when using 'operations'.r;   r�   zIWhich memory store: 'memory' for personal notes, 'user' for user profile.ru   z™Required for 'add' and 'patch'. For 'add', the new entry. For 'patch', the text that replaces old_text; the rest of the entry is kept. Alias: 'new_text'.rC   z¯REQUIRED for 'patch' and 'remove': text from one entry. 'patch' replaces exactly this span (it must occur once in the entry); 'remove' deletes the whole entry. Omit for 'add'.rˆ   z5Alias for 'content'. If both are set, 'content' wins.r?   ÚarrayzÑBatch shape: a list of operations applied atomically in one call against the final char budget. Preferred when making multiple changes or consolidating to make room. Each item is {action, content?, old_text?}.Úitemsz/Required for add and patch, as 'content' above.z"Alias for 'content' in a batch op.zAs 'old_text' above.ÚrequiredÚadditionalPropertiesFc                óF   € V ^8„  d   QhR\         \        \        3,          /# r   r…   )r   s   "r   r   r   Ê  s   € ÷ Bñ B¬¬S´#¨X­ñ Br   c                 óä  € \         P                  4       ;'       g    \        4       p \         P                  R4       \	        RV 4       UUu. uF  w  rV'       g   K  VNK  	  ppp\
        P                  ! \        R,          4      pVR,          R,          \        R,          reW5R&   \        P                  \        V4      4      ;p'       d   Vw  VR&   pVP                  RV4      pRVRV/# u uppi )	zENarrow the advertised target surface using the availability snapshot.Nrý   r   r;   rü   r  z‹TARGETS: 'user' = who the user is (name, role, preferences, style). 'memory' = your notes (environment, conventions, tool quirks, lessons).)r<   r�   )rë   r/   r-   rh   rH   ÚcopyÚdeepcopyÚMEMORY_SCHEMAÚ_SINGLE_TARGET_TEXTrÇ   rz   )	rì   ÚtÚonÚtargetsrý   Útarget_schemarü   ÚnarrowedÚreplacements	            r   Ú_build_memory_schema_overridesr  Ê  sÚ   € ä!×%Ñ%Ó'×KÐKÔ+IÓ+K€EÜ×Ñ˜dÔ#Ü!Ð"4°eÔ<ÔCÑ<‘U�QÄ�qˆqÑ<€GÑCÜ—’œ}¨\Õ:Ó;€JØ!+¨LÕ!9¸(Õ!CÄ]ÐS`ÕEa�;Ø#�&ÑÜ&×*Ñ*¬5°«>Ó:Ð:€xÖ:Ø4<Ñ1ˆ�mÑ$ kØ!×)Ñ)ðFØGRóTˆð ˜;¨°jÐAÐAùó Ds   ÁC,ÁC,)Úregistryri   c                 óÈ   € \        RR V P                  R R4      RV P                  R4      RVP                  R4      /R Uu/ uF  q"V P                  V4      bK  	  upB # u upi )r=   rD   r;   r4   r   )ru   rC   rˆ   r?   )rÅ   r/   )ÚargsÚkwrç   s   &, r   rv   rv   à  sh   € œ{ñ  WØ�x‰x˜ "Ó%ð WØ.2¯h©h°xÓ.@ð WØHJÏÉÈwËð Wá#TÓ
UÑ#T˜aˆd�h‰h�q‹kŠ>Ñ#TÑ
Uò Wùâ
Us   Á Au   ðŸ§ )rû   ÚtoolsetÚschemaÚhandlerÚcheck_fnÚemojiÚdynamic_schema_overridesc                óŽ   € V ^8„  d   Qh/ ^ \         9   d1   \        \        \        \        \        3,          ,          ,          ;R&   # )r   rë   )Ú__conditional_annotations__r   r
   rÇ   rä   )r   s   "r   r   r      s7   € ÷ Hñ H÷B rÒ q”z¤(¬5´´t°Õ+<Õ"=Õ>Ñ qòCHr   rs   )rz   r~   r�   )r<   NN)Nr<   NNNNN)rq   r�   r~   )r<   )z8The enabled built-in store: 'memory' for personal notes.zeTARGET: only 'memory' is enabled for personal notes (environment, conventions, tool quirks, lessons).)r�   )z4The enabled built-in store: 'user' for user profile.zWTARGET: only 'user' is enabled for user profile facts (name, role, preferences, style).)?r  Ú__doc__r	  rK   ÚloggingÚcontextvarsr   Úpathlibr   Úhermes_constantsr   Útypingr   r   r	   r
   r   Úutilsr   rò   r   ÚmsvcrtÚfcntlÚImportErrorÚ	getLoggerÚ__name__r·   rë   r   Útools.memory_tool_storer   r   r   r    r!   r"   r5   rP   rp   r›   rŒ   rœ   r¨   rI   r×   r¬   r¹   rÅ   rÊ   rÏ   rÁ   r,   r-   rí   rÕ   rú   r  r  r  r  ri   Úregisterr   )r  s   @r   Ú<module>r.     sõ  øðöHó
 Û Û Ý "Ý Ý ,ß 3Õ 3å !Ý ,ð 
€ðÛð 
×	Ò	˜8Ó	$€ñ
 BLÐLbÐlpÔAqÐ Ó qõ*÷
n÷ nõõ"Uõ(*ð0 
Ó[ÙOðQàÓtñqðrð ÓiÙXðZàÓpñOðPðQ€õ!÷	jõð0 4Ð ðLÐ õ
P÷(@÷Võ&fõ:õ
'Q÷T8÷tð ô ó ð ÷tõ@Cð* ˆHØð	4ð. Ø�ØØØ˜ØÒ2ØÐgðð
 Ø˜Ø˜ 6Ð*ØÐjðð
 Ø˜Øð   {ðð Ø˜Øð   Qðð Ø˜ØÐVðð Ø˜Øðað Ø˜HØ Ø  6¨8°VÒ=WÐ"XØ! F¨H°mÐEvÐ#wØ" V¨X°}ÐFjÐ$kØ" V¨X°}ÐF\Ð$]ð	#ð   
Ø*¨Eð
ðð/*
ðV 	�X�Jð[.ð5I€ð\ ð ,ð ð kð	lÐ õB÷  0à × Ò Ø	ØØñWð 'Ø
Ø;÷	=øðK ô Ø€EðÞøØô Ûðúð	ús*   ÁF+ Æ+	GÆ5F<Æ<GÇGÇGÇG