
    epjt                        d Z ddlmZ ddlmZ ddlmZmZmZ dZ	dZ
 G d dee          Zd dZd!dZd"dZddddd#dZdS )$uF  Shared session activity observation contract (#72016 / #72039).

Observation-only: timestamp + bounded description/provenance.
Notification, timeout, kill, and retry policy stay in their own components.
Consumers distinguish work (API / tool / compacting / stalled) from the
description text itself — there is no separate phase enum.

Provenance is a small closed enum of *noun* sources (where the stamp came
from). The default agent activity clock (``_touch_activity``) stamps
``unknown`` unless a caller passes an explicit ``provenance=``; named
values are for special writers.
    )annotations)Enum)AnyMappingOptionalx   g      N@c                  "    e Zd ZdZdZdZdZdZdS )ActivityProvenancez3Where a durable/in-memory activity stamp came from.unknownzagent.compressionzagent.compression_timeoutzagent.compression_cooldownN)__name__
__module____qualname____doc__UNKNOWNAGENT_COMPRESSIONAGENT_COMPRESSION_TIMEOUTAGENT_COMPRESSION_COOLDOWN     </home/thesage/.hermes/hermes-agent/agent/session_activity.pyr
   r
       s-        ==G+ ;!=r   r
   descriptionOptional[str]returnstrc                    | pd                                 }t          |          t          k    r|S |dt          dz
           dz   S )z?Clamp free-form activity text to the shared description budget. N   u   …)striplenACTIVITY_DESCRIPTION_MAX)r   texts     r   bound_activity_descriptionr"   *   sK    2$$&&D
4yy,,,.*Q../%77r   
provenance"Optional[ActivityProvenance | str]c                    t          | t                    r| S | pd                                }	 t          |          S # t          $ r t          j        cY S w xY w)zBReturn a known provenance, or ``UNKNOWN`` when unset/unrecognized.r   )
isinstancer
   r   
ValueErrorr   )r#   values     r   normalize_activity_provenancer)   2   sp     *011 2$$&&E*!%((( * * *!))))*s   > AAagentr   Nonec                8    	 d| _         dS # t          $ r Y dS w xY w)am  Clear the agent's durable SessionDB activity persist rate-limit window.

    The next ``_touch_activity`` / ``_persist_session_activity_if_due`` will
    write through even if a stamp landed within the last 60s. Used for
    terminal compression labels that must not stay stuck on mid-compress
    text (e.g. "context compression in progress" after /compress).
    g        N)#_session_activity_last_persist_mono	Exception)r*   s    r   %reset_session_activity_persist_windowr/   ?   s7    47111   s    
N)last_activity_provenancenowextralast_activity_atOptional[float]last_activity_descriptionr0   r1   r2   Optional[Mapping[str, Any]]dict[str, Any]c           	     Z   ddl }| t          |           nd}t          ||n|                                           }t          |          }t          |          }	|t	          ||z
  d          nd}
|||	j        |
||||	j        d}|r"|                    t          |                     |S )zABuild the shared activity snapshot (plus optional caller extras).r   Nr   )r3   r5   r0   seconds_since_activitylast_activity_tslast_activity_descr   r#   )timefloatr"   r)   roundr(   updatedict)r3   r5   r0   r1   r2   _timewhenclockdescprovelapsedsnaps               r   build_activity_snapshotrH   M   s     &6&B5!"""D##ejjll;;E%&?@@D()ABBD(,(8eEDL!$$$dG %)$(J") "j
 
D  !DKK   Kr   )r   r   r   r   )r#   r$   r   r
   )r*   r   r   r+   )r3   r4   r5   r   r0   r$   r1   r4   r2   r6   r   r7   )r   
__future__r   enumr   typingr   r   r   r    /SESSION_ACTIVITY_HEARTBEAT_MIN_INTERVAL_SECONDSr   r
   r"   r)   r/   rH   r   r   r   <module>rM      s     # " " " " "       ) ) ) ) ) ) ) ) ) )  37 /> > > > >d > > >8 8 8 8
* 
* 
* 
*   $ DH)-       r   