§
    éŽ’jo  ã                   óX   — d Z ddlZddlZddlmZ ddlmZ ddlm	Z
  G d„ d¦  «        ZdS )a  Manages the lifecycle of registered triggers.

The TriggerRunner starts all triggers as concurrent asyncio tasks at
session start and cancels them at session end. Unhandled exceptions in
a trigger are logged but do not crash the session or restart the trigger.
é    N)ÚSequence©Ú
connection)Útriggersc                   óº   — e Zd ZdZdeej                 dej        ddfd„Z	dd„Z
dd„Zdd	„Zdd
„Zedefd„¦   «         Zedej        dej        ddfd„¦   «         ZdS )ÚTriggerRunnerz8Manages registration, startup, and shutdown of triggers.r   r   ÚreturnNc                 óJ   — t          |¦  «        | _        || _        g | _        dS )z›Initializes the TriggerRunner.

    Args:
      triggers: Sequence of trigger functions to manage.
      connection: The live connection to the agent.
    N)ÚlistÚ	_triggersÚ_connectionÚ_tasks)Úselfr   r   s      úXC:\Projects\DSCons\.venv\Lib\site-packages\google\antigravity\triggers\trigger_runner.pyÚ__init__zTriggerRunner.__init__!   s$   € õ ˜(‘^”^€D„NØ!€DÔØ,.€D„K€K€Kó    c           
   ƒ   ó*  K  — | j         rt          d¦  «        ‚| j        D ]r}t          j        | j        ¬¦  «        }t          j        |                      ||¦  «        dt          |dd¦  «        › �¬¦  «        }| j          
                    |¦  «         ŒsdS )u±  Start all triggers as concurrent asyncio tasks.

    Each trigger receives its own TriggerContext. If a trigger raises
    an unhandled exception, it is logged and the task stops â€” no
    auto-restart, no impact on other triggers or the session.

    Triggers run as independent asyncio tasks with no ordering
    guarantees â€” they may execute in any order.

    Raises:
      RuntimeError: If the runner is already started.
    z!TriggerRunner is already started.r   ztrigger-Ú__name__Úunknown)ÚnameN)r   ÚRuntimeErrorr   Útriggers_moduleÚTriggerContextr   ÚasyncioÚcreate_taskÚ_run_triggerÚgetattrÚappend)r   ÚtriggerÚctxÚtasks       r   ÚstartzTriggerRunner.start0   s·   è è € ð „{ð >ÝÐ<Ñ=Ô=Ð=à”>ð ð ˆÝÔ*ØÔ%ðñ ô €cõ Ô Ø
×
Ò
˜G SÑ
)Ô
)ØC�' '¨:°yÑAÔAÐCÐCðñ ô €dð „k×Ò˜ÑÔÐÐðð r   c              ƒ   óê   K  — | j         sdS | j         D ]*}|                     ¦   «         s|                     ¦   «          Œ+t          j        | j         ddiŽƒ d{V —† | j                              ¦   «          dS )zœCancel all trigger tasks and wait for them to finish.

    Safe to call multiple times. After stop(), the runner can be
    started again with start().
    NÚreturn_exceptionsT)r   ÚdoneÚcancelr   ÚgatherÚclear)r   r!   s     r   ÚstopzTriggerRunner.stopJ   s‹   è è € ð Œ;ð Ø€fà”ð ð ˆØ�YŠY‰[Œ[ð Ø�Š‰Œˆøõ Œ.˜$œ+Ð
>¸Ð
>Ð
>Ð>Ð>Ð>Ð>Ð>Ð>Ð>Ø„K×ÒÑÔÐÐÐr   c              ƒ   ó>   K  — |                       ¦   «         ƒ d{V —† | S )z\Start triggers on entering the context.

    Returns:
      The TriggerRunner instance.
    N)r"   ©r   s    r   Ú
__aenter__zTriggerRunner.__aenter__[   s-   è è € ð �*Š*‰,Œ,ÐÐÐÐÐÐÐØ€Kr   c              ƒ   ó>   K  — |                       ¦   «         ƒ d{V —† dS )z²Stop triggers on exiting the context.

    Args:
      exc_type: The exception type, if any.
      exc_val: The exception value, if any.
      exc_tb: The traceback, if any.
    N)r)   )r   Úexc_typeÚexc_valÚexc_tbs       r   Ú	__aexit__zTriggerRunner.__aexit__d   s.   è è € ð �)Š)‰+Œ+ÐÐÐÐÐÐÐÐÐr   c                 ó>   — t          d„ | j        D ¦   «         ¦  «        S )z%True if any trigger tasks are active.c              3   ó@   K  — | ]}|                      ¦   «          V — Œd S )N)r%   )Ú.0r!   s     r   ú	<genexpr>z+TriggerRunner.is_running.<locals>.<genexpr>q   s,   è è € Ð7Ð7 4�4—9’9‘;”;ˆÐ7Ð7Ð7Ð7Ð7Ð7r   )Úanyr   r+   s    r   Ú
is_runningzTriggerRunner.is_runningn   s#   € õ Ð7Ð7¨4¬;Ð7Ñ7Ô7Ñ7Ô7Ð7r   r   r    c              ƒ   óþ   K  — t          | dt          | ¦  «        ¦  «        }	  | |¦  «        ƒ d{V —† dS # t          j        $ r t	          j        d|¦  «         ‚ t          $ r t	          j        d|¦  «         Y dS w xY w)a(  Wraps a trigger call with error handling.

    CancelledError is allowed to propagate so that trigger-internal
    cleanup code works correctly. Non-cancellation exceptions are
    logged and swallowed.

    Args:
      trigger: The trigger function to run.
      ctx: The trigger's context.
    r   NzTrigger '%s' cancelled.z-Trigger '%s' failed with unhandled exception.)r   Úreprr   ÚCancelledErrorÚloggingÚinfoÚ	ExceptionÚ	exception)r   r    Útrigger_names      r   r   zTriggerRunner._run_triggers   s¹   è è € õ ˜7 Jµ°W±´Ñ>Ô>€LðØˆG�C‰LŒLÐÐÐÐÐÐÐÐÐøÝÔ!ð ð ð Ý„lÐ,¨lÑ;Ô;Ð;ØÝð ð ð ÝÔØ
9¸<ñô ð ð ð ð ðøøøs   ¢5 µAA<Á;A<)r	   N)r	   r   )r   Ú
__module__Ú__qualname__Ú__doc__r   r   ÚTriggerÚconnection_moduleÚ
Connectionr   r"   r)   r,   r1   ÚpropertyÚboolr7   Ústaticmethodr   r   © r   r   r   r      s  € € € € € Ø@Ð@ð/à˜Ô0Ô1ð/ð $Ô.ð/ð ð	/ð /ð /ð /ðð ð ð ð4ð ð ð ð"ð ð ð ðð ð ð ð ð8˜$ð 8ð 8ð 8ñ „8ð8ð ðØÔ&ðàÔ)ðð ðð ð ñ „<ðð ð r   r   )rB   r   r;   Útypingr   Úgoogle.antigravity.connectionsr   rD   Úgoogle.antigravity.triggersr   r   r   rI   r   r   ú<module>rM      s•   ððð ð €€€Ø €€€Ø Ð Ð Ð Ð Ð à JÐ JÐ JÐ JÐ JÐ JØ CÐ CÐ CÐ CÐ CÐ Cðmð mð mð mð mñ mô mð mð mð mr   