Ë
    Tž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
 ddlmZ ddlmZ  ed	«      Z G d
„ de«      Zy)uÜ   
Genesis Persistent Context Architecture â€” MVFL Interceptor
Story 3.06 â€” Track B

Wires the MVFL error-correction pipeline into the interceptor chain.
Priority 90 â€” runs late, AFTER business logic, checks results.
é    N)ÚdatetimeÚtimezone)ÚPath)ÚBaseInterceptorÚInterceptorMetadata)ÚMVFLTrigger)ÚVoyagerDefense)ÚCorrectionLoopz(/mnt/e/genesis-system/data/observabilityc                   óž   — e Zd ZdZ	 	 	 ddededefd„Zede	fd„«       Z
d	edefd
„Zded	eddfd„Zded	edefd„Zdedefd„Zd	ededdfd„Zy)ÚMVFLInterceptoruí   
    Architecturally forced error correction.
    Priority 90 â€” runs late, AFTER business logic, checks results.

    Wires together MVFLTrigger, VoyagerDefense, and CorrectionLoop into
    the standard interceptor chain contract.
    NÚtriggerÚvoyagerÚcorrection_loopc                 óv   — |xs
 t        «       | _        |xs
 t        «       | _        |xs
 t	        «       | _        y )N)r   Ú_triggerr	   Ú_voyagerr
   Ú_correction_loop)Úselfr   r   r   s       ú3/mnt/e/genesis-system/core/mvfl/mvfl_interceptor.pyÚ__init__zMVFLInterceptor.__init__   s1   € ð  Ò0¤;£=ˆŒØÒ3¤>Ó#3ˆŒØ /Ò C´>Ó3CˆÕó    Úreturnc                 ó   — t        dd¬«      S )NÚmvfléZ   )ÚnameÚpriority)r   )r   s    r   ÚmetadatazMVFLInterceptor.metadata'   s   € ä"¨¸Ô<Ð<r   Útask_payloadc              ƒ   ó   K  — |S ­w)u}   
        No-op â€” MVFL acts on results, not inputs.
        Returns task_payload unchanged (identity pass-through).
        © )r   r   s     r   Úpre_executezMVFLInterceptor.pre_execute+   s   è ø€ ð
 Ðùó   ‚Úresultc              ƒ   ó  K  — | j                   j                  ||«      }| j                  j                  |«      }|j                  xs |j
                  }| j                  ||||«       |rž| j                  j                  |||«      ƒ d{  –—† }|j                  r0|j                  |j                  «       d|d<   |j                  |d<   yd|d<   |j                  |d<   |j                  r|j                  |j                  «       yyy7 Œ~­w)u  
        Evaluate result via MVFLTrigger + VoyagerDefense.
        If either gate fires â†’ run CorrectionLoop and mutate result in-place.
        Records every decision to events.jsonl.

        Signature matches BaseInterceptor: result first, task_payload second.
        NTÚmvfl_correctedÚmvfl_attemptsÚmvfl_escalated)r   Úevaluater   ÚscoreÚ	triggeredÚshould_blockÚ_log_decisionr   ÚrunÚsuccessÚupdateÚoutputÚattempts)r   r$   r   Útrigger_resultÚvoyager_scoreÚblockedÚ
corrections          r   Úpost_executezMVFLInterceptor.post_execute2   s   è ø€ ð Ÿ™×/Ñ/°¸ÓEˆØŸ™×+Ñ+¨FÓ3ˆà ×*Ñ*ÒH¨m×.HÑ.Hˆð 	×Ñ˜<¨¸ÈÔPáØ#×4Ñ4×8Ñ8Ø˜f nó ÷ ˆJð ×!Ò!à—‘˜j×/Ñ/Ô0Ø+/Ð'Ñ(Ø*4×*=Ñ*=Ò'à+/Ð'Ñ(Ø*4×*=Ñ*=Ñ'Ø×$Ò$Ø—M‘M *×"3Ñ"3Õ4ð %ð ðús   ‚BDÂ
D	ÂA?DÚerrorc              ƒ   óP  K  — dt        |«      dœ}| j                  j                  ||«      }| j                  ||d|j                  «       |j                  r?| j
                  j                  |||«      ƒ d{  –—† }|j                  r|j                  S |S t        |«      |dœS 7 Œ,­w)uÑ   
        Evaluate error context via MVFLTrigger.
        If triggered â†’ run CorrectionLoop and return correction output.

        Signature matches BaseInterceptor: error first, task_payload second.
        r8   )Ústatusr8   N)r8   r   )Ústrr   r)   r-   r+   r   r.   r1   )r   r8   r   Úerror_outputr3   r6   s         r   Úon_errorzMVFLInterceptor.on_errorQ   s    è ø€ ð #*´C¸³JÑ?ˆØŸ™×/Ñ/°¸lÓKˆà×Ñ˜<¨¸¸~×?WÑ?WÔXà×#Ò#Ø#×4Ñ4×8Ñ8Ø˜l¨Nó ÷ ˆJð )3×(9Ò(9:×$Ñ$ÐK¸|ÐKä˜U›°\ÑBÐBðús   ‚A5B&Á7B$Á8-B&Úcorrection_payloadc              ƒ   ó   K  — |S ­w)u   
        Passthrough â€” correction handling is fully encapsulated in CorrectionLoop.
        Returns the correction_payload unchanged.
        r!   )r   r>   s     r   Úon_correctionzMVFLInterceptor.on_correctione   s   è ø€ ð
 "Ð!ùr#   r5   c                 óÖ  — 	 t         j                  dd¬«       t        j                  t        j
                  «      j                  «       d|j                  dd«      |r|j                  nd|r|j                  nd|r|j                  nd|d	œ}t        t         d
z  d«      5 }|j                  t        j                  |«      dz   «       ddd«       y# 1 sw Y   yxY w# t        $ r Y yw xY w)u†   
        Append one JSON line to EVENTS_DIR/events.jsonl.
        Never raises â€” telemetry must not interrupt the pipeline.
        T)ÚparentsÚexist_okÚmvfl_decisionÚtask_idÚunknownFNg        )Ú	timestampÚ
event_typerE   r+   Útrigger_typer4   r5   zevents.jsonlÚaÚ
)Ú
EVENTS_DIRÚmkdirr   Únowr   ÚutcÚ	isoformatÚgetr+   rI   r*   ÚopenÚwriteÚjsonÚdumpsÚ	Exception)r   r   r3   r4   r5   ÚeventÚfs          r   r-   zMVFLInterceptor._log_decisionp   sË   € ð	Ü×Ñ T°DÐÔ9ä%Ÿ\™\¬(¯,©,Ó7×AÑAÓCØ-Ø'×+Ñ+¨I°yÓAÙ9G˜^×5Ò5ÈUÙ?M × ;Ò ;ÐSWÙ8E ×!4Ò!4È3Ø"ñˆEô ”j >Ñ1°3Ó7ð 2¸1Ø—‘œŸ
™
 5Ó)¨DÑ0Ô1÷2÷ 2ñ 2ûäò 	Ùð	ús0   ‚BC Â(CÃC ÃCÃC ÃC Ã	C(Ã'C()NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r
   r   Úpropertyr   r   Údictr"   r7   rV   r=   r@   Úboolr-   r!   r   r   r   r      sÒ   „ ñð  $Ø"&Ø*.ñ	DàðDð  ðDð (ó	Dð ð=Ð-ò =ó ð=ð¨dð °tó ð5¨ð 5¸Tð 5Àdó 5ð>C Ið C¸Tð CÀdó Cð("°dð "¸tó "ðàðð
 ðð 
ôr   r   )r\   rT   r   r   Úpathlibr   Ú"core.interceptors.base_interceptorr   r   Úcore.mvfl.mvfl_triggerr   Úcore.mvfl.voyager_defenser	   Úcore.mvfl.correction_loopr
   rL   r   r!   r   r   ú<module>re      s:   ðñó ß 'Ý ç SÝ .Ý 4Ý 4áÐ<Ó=€
ôuoõ ur   