
    i              	           d Z ddlZddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
  e
       Zded	dfd
Z	 	 ddedee   dee   d	efdZded	efdZy)u  
Genesis Persistent Context Architecture — Interceptors Package
Story 1.03 — Track B

Exports:
  BaseInterceptor, InterceptorMetadata — abstract base + metadata dataclass
  InterceptorChain                     — ordered execution engine
  GLOBAL_CHAIN                         — module-level singleton chain
  register_interceptor()               — convenience helper to add to GLOBAL_CHAIN
  dispatch_to_swarm()                  — central dispatch function
    N)datetimetimezone)Optional   )BaseInterceptorInterceptorMetadata)InterceptorChaininterceptorreturnc                 .    t         j                  |        y)zCConvenience helper: add an interceptor to the process-global chain.N)GLOBAL_CHAINregister)r
   s    3/mnt/e/genesis-system/core/interceptors/__init__.pyregister_interceptorr      s    +&    task_payloadtiercontextc                   K   d| vr t        t        j                               | d<   t        j                  t
        j                        j                         | d<   ||| d<   | d   }	 t        j                  |        d{   }t        |       d{   }t        j                  ||       d{    i ||ddS 7 >7 -7 # t        $ r/}t        j                  ||        d{  7  }|d|dcY d}~S d}~ww xY ww)	a  Central dispatch function.

    Assigns a UUID4 task_id if one is not already present, stamps
    ``dispatched_at`` in UTC ISO-8601, optionally tags the payload with
    ``tier``, then runs the interceptor chain pre/post hooks around the
    internal task executor.

    Returns a result dict that always includes ``task_id`` and ``status``.
    On success: ``{"status": "completed", "task_id": ..., ...}``
    On error:   ``{"status": "error",     "task_id": ..., "correction": ...}``
    task_iddispatched_atNr   	completed)r   statuserror)r   r   
correction)struuiduuid4r   nowr   utc	isoformatr   execute_pre_execute_taskexecute_post	Exceptionexecute_error)r   r   r   r   enrichedresultexcr   s           r   dispatch_to_swarmr*      s     " $"%djjl"3Y$,LL$>$H$H$JL!#V9%GQ%11,??$X..''999D&DWDD @.9 Q'55c<HHH
"gZPPQsx   A%D (C  B?C CC 1C2C >D ?C C C 	C=C8'C*(
C82C=3D 8C==D c                 V   K   | j                  dd      | j                  dd      ddS w)u   Stub executor — passthrough until real Gemini/Opus dispatch is wired in.

    Returns the prompt text (if present) as ``output``.  Will be replaced by
    the real execution layer in a later story.
    r   unknownprompt r   )r   outputr   )get)r   s    r   r#   r#   A   s5       ##Iy9""8R0 s   '))NN)__doc__r   r   r   typingr   base_interceptorr   r   interceptor_chainr	   r   r   dictr   r*   r#    r   r   <module>r7      s   
  '  B /
  !'o '$ ' " Q Q
3- Q d^ Q 
	 QF
d 
t 
r   