§
    ÷žyjì  ã            	       ó²   — d Z ddlZddlZddlmZ ddlmZmZmZ  ej        e	¦  «        Z
dedefd„Zdedefd„Z	 dd	eeeef                  d
ededefd„ZdS )zãTrajectory saving utilities and static helpers.

_convert_to_trajectory_format stays as an AIAgent method (batch_runner.py
calls agent._convert_to_trajectory_format). Only the static helpers and
the file-write logic live here.
é    N)Údatetime)ÚAnyÚDictÚListÚcontentÚreturnc                 óf   — | rd| vr| S |                       dd¦  «                              dd¦  «        S )z4Convert <REASONING_SCRATCHPAD> tags to <think> tags.ú<REASONING_SCRATCHPAD>z<think>ú</REASONING_SCRATCHPAD>z</think>)Úreplace©r   s    ú6/home/ragecks/.hermes/hermes-agent/agent/trajectory.pyÚconvert_scratchpad_to_thinkr      sA   € àð Ð.°gÐ=Ð=ØˆØ�?Š?Ð3°YÑ?Ô?×GÒGÐHaÐcmÑnÔnÐnó    c                 ó   — | sdS d| v od| vS )zMCheck if content has an opening <REASONING_SCRATCHPAD> without a closing tag.Fr
   r   © r   s    r   Úhas_incomplete_scratchpadr      s&   € àð ØˆuØ# wÐ.Ð[Ð3LÐT[Ð3[Ð[r   Ú
trajectoryÚmodelÚ	completedÚfilenamec                 ó´  — |€|rdnd}| t          j        ¦   «                              ¦   «         ||dœ}	 t          |dd¬¦  «        5 }|                     t          j        |d¬	¦  «        d
z   ¦  «         ddd¦  «         n# 1 swxY w Y   t                               d|¦  «         dS # t          $ r&}t           
                    d|¦  «         Y d}~dS d}~ww xY w)ay  Append a trajectory entry to a JSONL file.

    Args:
        trajectory: The ShareGPT-format conversation list.
        model: Model name for metadata.
        completed: Whether the conversation completed successfully.
        filename: Override output filename. Defaults to trajectory_samples.jsonl
                  or failed_trajectories.jsonl based on ``completed``.
    Nztrajectory_samples.jsonlzfailed_trajectories.jsonl)ÚconversationsÚ	timestampr   r   Úazutf-8)ÚencodingF)Úensure_asciiÚ
zTrajectory saved to %szFailed to save trajectory: %s)r   ÚnowÚ	isoformatÚopenÚwriteÚjsonÚdumpsÚloggerÚinfoÚ	ExceptionÚwarning)r   r   r   r   ÚentryÚfÚes          r   Úsave_trajectoryr,      sJ  € ð ÐØ1:Ð[Ð-Ð-Ð@[ˆð $Ý”\‘^”^×-Ò-Ñ/Ô/ØØð	ð €Eð;Ý�(˜C¨'Ð2Ñ2Ô2ð 	B°aØ�GŠG•D”J˜u°5Ð9Ñ9Ô9¸DÑ@ÑAÔAÐAð	Bð 	Bð 	Bñ 	Bô 	Bð 	Bð 	Bð 	Bð 	Bð 	Bð 	Bøøøð 	Bð 	Bð 	Bð 	Bå�ŠÐ,¨hÑ7Ô7Ð7Ð7Ð7øÝð ;ð ;ð ;Ý�ŠÐ6¸Ñ:Ô:Ð:Ð:Ð:Ð:Ð:Ð:Ð:øøøøð;øøøs;   ´B' Á-A?Á3B' Á?BÂB' ÂBÂB' Â'
CÂ1CÃC)N)Ú__doc__r#   Úloggingr   Útypingr   r   r   Ú	getLoggerÚ__name__r%   Ústrr   Úboolr   r,   r   r   r   ú<module>r4      s  ððð ð €€€Ø €€€Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à	ˆÔ	˜8Ñ	$Ô	$€ðo¨ð o°ð oð oð oð oð\ sð \¨tð \ð \ð \ð \ð 6:ð;ð ;  T¨#¨s¨(¤^Ô 4ð ;¸Sð ;Ø#ð;Ø/2ð;ð ;ð ;ð ;ð ;ð ;r   